awk print ' char
18,805
Solution 1
You have to quote the single quote to protect it from the shell. That means instead of
$ cat file.log | awk '{print nir's $1}'
you have to write something like
$ awk '{print "nir'"'"'s",$1}' file.log
Solution 2
There are two problems here:
- You can't pass
'
within'
, which you are also using to quote the awk syntax. You need to leave the quoting first; - You need to quote strings in awk.
It seems like this is what you want:
awk '{print "nir'\''s " $1}'
Solution 3
This should work:
cat file.log | awk '{print "nir\047s " $1}'
Related videos on Youtube
Author by
Nir
Updated on September 18, 2022Comments
-
Nir over 1 year
I want to print:
cat file.log | awk '{print nir's $1}'
output should be:
nir's aaa nir's bbb nir's abc nir's dbc
The problem is with the
'
innir's
.I also tried:
cat file.log | awk '{print nir\'s $1}' cat file.log | awk '{print nir''s $1}' cat file.log | awk '{print nir'''s $1}'
-
slm over 10 yearsUseless use of
cat
. You don't need to cat the filefile.log
toawk
. The commandawk
can deal with the filename directly. -
clerksx over 10 years@slm Not to mention that it's not merely an issue of semantics, some optimisations may not be able to be applied when reading from a stream vs. reading from a file.
-
maxschlepzig over 10 years@slm, you are right. I've removed one useless use in my answer - the first one is quoted from the question.