0
#!/usr/bin/env bash
for year in all/*
do
  echo -ne `basename $year .gz`"\t"
  gunzip -c $year | \ awk '{ temp = substr($0, 88, 5) + 0;
      q = substr($0, 93, 1);
      if (temp !=9999 && q ~ /[01459]/ && temp > max) max = temp }
    END { print max }'
done

I've a small doubt over this Awk script for reading a file which I found in a Hadoop book. In line number 5 (the one which starts with gunzip), after the |, what is the purpose of the backslash \ before awk?

tripleee
  • 175,061
  • 34
  • 275
  • 318
A_____
  • 364
  • 3
  • 19
  • 1
    `\ awk` means execute " awk" (with a space as the first character). It looks odd, but it's *possible* to have a command with that name. – Biffen Jan 28 '15 at 09:12
  • You may see `\awk`, which would be explained by [\curl … | bash … what's the slash for?](http://stackoverflow.com/q/15951772/1983854) – fedorqui Jan 28 '15 at 09:22
  • Thanks Biffen for clarification,If I remove \ here, I think it will not matter. Am I right? – A_____ Jan 28 '15 at 09:23
  • It will "matter", in that it will invoke the command `awk` instead of the command (space) `awk` which most likely does not exist. – tripleee Jan 28 '15 at 09:52

1 Answers1

1

Either the book contains a typo, or the script was incompletely transcribed. A backslash may optionally be used for line wrapping:

echo "moo" | \
wc -l

which is equivalent to

echo "moo" | wc -l

but in this particular case, the backslash is completely optional after a pipe, so you might as well write

echo "moo" |
wc -l

In any event, the way you have the script in your question, the backslash is erroneous.

tripleee
  • 175,061
  • 34
  • 275
  • 318