[Ilugc] Awk example

  • From: binand@xxxxxxxxx (Binand Sethumadhavan)
  • Date: Thu Feb 17 13:32:38 2005

On Thu, 17 Feb 2005 12:20:01 +0530, Anthony Ashok
<Anthony.Ashok@xxxxxxxxxxxxxxx> wrote:

if i give the above file as input to awk the awk program has to take the
"|' as a record separator "^" as field separator.

Hmm...

binand@bastille[~/awk]:[02:59](34) awk 'BEGIN { RS = "|"; FS = "^" } {
for (i = 1; i <= NF; i++) print i, gensub ("[[:space:]]*", "", "g",
$i) }' myfile.txt
1 one
2 two
3 three
4 four
1 five
2 six

Is that OK? 

The code above is beerware. :)

Binand

Other related posts: