What is the difference between sed and awk?

sed is a stream editor. It works with streams of characters on a per-line basis. It has a primitive programming language that includes goto-style loops and simple conditionals (in addition to pattern matching and address matching). There are essentially only two “variables”: pattern space and hold space. Readability of scripts can be difficult. Mathematical operations are … Read more

Use of `NF` in awk command

-v var=val–assign var=val Set the variable var to the value val before execution of the program begins. NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a record. In your first program, you execute {NF=3} after each … Read more

Printing the last column of a line in a file

You don’t see anything, because of buffering. The output is shown, when there are enough lines or end of file is reached. tail -f means wait for more input, but there are no more lines in file and so the pipe to grep is never closed. If you omit -f from tail the output is shown immediately: @EdMorton is right of course. Awk can search for A1 as well, … Read more

Using awk to remove the Byte-order mark

Try this: On the first record (line), remove the BOM characters. Print every record. Or slightly shorter, using the knowledge that the default action in awk is to print the record: 1 is the shortest condition that always evaluates to true, so each record is printed. Enjoy! — ADDENDUM — Unicode Byte Order Mark (BOM) FAQ includes … Read more