1

I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip:

# gfhfhgfh
gfhfghgfhgfhgfh
MACs 
# access
USER CONSOLA *,!10.249.247.3,!10.249.245.65
/bin/false

I want to add an ip in the end of the line that contains as patron USER CONSOLE:

 USER CONSOLA *,!10.249.247.4,!10.249.245.65,!10.249.245.90,

I only manage to add the ip in the whole document at the moment but not in that particular line the code used is

sed 's/\r\?$/,!10.10.11.1/' file.txt 

1 Answers1

2

Using sed you'd need something like the following:

sed '/USER CONSOLA/s/$/,!10.249.245.90,/' file.txt

First we'll match the pattern we want to append to. Then we use s/$/.. which means add !10.249.245.90, as is to the end of the line.

Here is another awk solution:

awk '/USER CONSOLA/{x=x; print $0",!10.249.245.90,";next}1' file.txt
Valentin Bajrami
  • 4,045
  • 1
  • 18
  • 26