-1

for this command

$ grep ^r lab3.tr | grep "2 6" -c | awk "{s+=$6}END{print s}"

I am getting this error

awk: line 1: syntax error at or near }

and what does "h" stand for in the following line of trace file

h 0.106 1 7 cbr 100 ------- 1 1.0 5.0 6 6

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • 1
    Your command is purely based on the format of your file, how do you expect us to understand the format of your file? :-) – Dominique Dec 22 '21 at 08:39
  • »» **h** 0.106 1 7 cbr 100 .. «« : Line starts with **h** in a trace file .... is usually an "out.nam" trace http://nsnam.sourceforge.net/wiki/index.php/NS-2_Trace_Formats – Knud Larsen Dec 22 '21 at 10:11
  • Please read https://mywiki.wooledge.org/Quotes. – Ed Morton Dec 22 '21 at 12:37
  • Also please ask 1 question at a time (no "**and** what does h stand for"). – Ed Morton Dec 22 '21 at 12:39
  • @Vijay Patil : Please see the ns2 "throughput awk" overview https://drive.google.com/file/d/1GbaWW6S65yMcIcOE7zSLi0C-KibiN00A/view?usp=sharing : ~25 different throughput scripts ..... to fit the most trace formats. .... Package, ns2 analyzing scripts https://drive.google.com/file/d/1uuVmyH8QPe4SRz2g1dnpfCIMvP26pCDj/view?usp=sharing – Knud Larsen Dec 28 '21 at 09:14

1 Answers1

2

You are using soft quotes around your awk-code so the shell interprets $6. As this argument is either empty or an unusable value, you receive said error. Use hard quotes for awk-code instead.

Example:

 $echo 1 2 3 | awk "{print $1}"
 1 2 3

=> shell interprets $1, however it is empty and thus only print is executed and it outputs the whole record.

$echo 1 2 3 | awk '{print $1}'
1

=> awk interprets $1 as field in record and thus it outputs the first field.

FelixJN
  • 540
  • 3
  • 16