I am having trouble printing (or searching) for sequences containing backslashes when using awk For example -
echo "test\test" | awk '{ gsub(/\\\\t/, "\\\\&"); print }'
will give the result:
test est
because the \t will be interperted as tab. I want to be able to have the string as is, meaning:
test\test
The echo command is just another way for me to check a 1 liner for the awk command to see if it can find a pattern such as \t in a file (using a bash script). To be more sprcific - If I want to have an awk cmd that needs to find a sequence of
\"
I am using the following:
awk -v st="$match_string" 'BEGIN {gsub(/\\\\"/,"\\\\&", st)} match($0,st {print;exit}' file.txt
but the cmd does not work: for a file with :
547 %$
236 \"
4523 &*
8876 (*
8756 "/
...
it will output:
> \"
8756 "/
What is the right way to use awk to find the
236 \"
Thanks
echo
to print a literal backslash (\
), you will need to escape that, as inecho "test\\test"
. – AdminBee Apr 27 '20 at 07:48