I'm trying to use AWK command, it's printing for me very well and what exact way I want
My question is, how can I know from script if the awk command I used has printed something without spoiling and change the way it prints ?
commands I used:
gawk 'BEGIN{RS=ORS="\n\n" {s=tolower($0)} s~/word1|word2/' input_file.log
I tried:
status=gawk 'BEGIN{RS=ORS="\n\n" {s=tolower($0)} s~/word1|word2/' input_file.log
if [ -z $status]
then
//status is empty or null, means nothing printed in awk command
echo "nothing"
else
//printed something in awk command
echo $status
the issue is that echo $status
prints in sequence all the lines, without the "new lines" between the lines
how can print the original prints from awk without spoiling it?
example: input file:
line 0 no words in here
line 1 starting
line 1 word1
line 2 no words here as well
line 3 starting
line 3 word2
line 3 end
line 4 nothing
line 5 nothing
command:
gawk 'BEGIN{RS=ORS="\n\n" {s=tolower($0)} s~/word1|word2/' input_file.log
expected output:
line 1 starting
line 1 word1
line 3 starting
line 3 word2
line 3 end
if I use:
stat=$(gawk 'BEGIN{RS=ORS="\n\n" {s=tolower($0)} s~/word1|word2/' input_file.log)
echo $stat
I get as output:
line 1 starting line 1 word1 line 3 starting line 3 word2 line 3 end
Thanks in advance!
RS=""
instead ofRS="\n\n"
your script will work the same but not be gawk-specific, 2) without word boundaries you'll match onfoobar
when looking forfoo
, 3) shell comments start with#
, not//
. - Ed Morton