-1

how do I search the following pattern by awk in a file.

'\b'

The pattern is one of the lines in a file.
I have to add text next to the pattern. Like this:

'\b' TEXT

Any of these commands are not working
1.

 awk -e '/'\b'/ { sub($1,$1" TEXT")} 1' -i inplace file

2.

 awk -e '/\'\\b\'/ {sub($1,$1" TEXT")} 1' -i inplace file
  • 2
    Show an example of your input and your expected output. – jordanm Feb 28 '17 at 5:38
0

The main problem is your incorrect use of sub:

awk '/\\b/ { $1 = $1" TEXT"} 1' file
0

Instead of using awk, you could use sed:

sed -i "s/'\\\\b'/& TEXT/" file

The trick is the 4 \ needed for both bash and sed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.