I would like to clear our first string in the quotes of this example:
set dstaddr "somename 10.108.41.90" "somename 10.108.148.53"
I would like following result:
set dstaddr "somename 10.108.148.53"
Could you please suggest how to to achieve it in bash? I am not interested only to remove first match in quotes but I am interested to remove matched IP address ranges from 10.108.41.0/24 or those that contain 41 in the third octet along with their names and remove them.
Logic should be : Okey script if you find hosts within subnet 10.108.41.0/24 please remove them from the string along with their names but do not touch other objects.
CodePudding user response:
Perl:
echo 'set dstaddr "somename 10.108.41.90" "somename 10.108.148.53"' \
| perl -pe 's/\b(\S )\b.*?\1/$1/'
set dstaddr "somename 10.108.148.53"
\b(\S )\bfinds a word and remembers it.*?\1finds some characters followed by that words/pattern/$1/replaces the patten with the captured word
CodePudding user response:
What about this:
awk '{print $1 " " $2 " " $5 " " $6}' test.txt
I simply use the space as a delimiter for the awk command. This obviously only works if somename does not contain any space character.
