-1

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.

Aserre
  • 4,916
  • 5
  • 33
  • 56

2 Answers2

0

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+)\b finds a word and remembers it
  • .*?\1 finds some characters followed by that word
  • s/pattern/$1/ replaces the patten with the captured word
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
0

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.

Dominique
  • 16,450
  • 15
  • 56
  • 112