Search This Blog

Showing posts with label output field separator. Show all posts
Showing posts with label output field separator. Show all posts

Friday, March 14, 2014

OFS (Output Field Seperator) in AWK

Like wise IFS, we can define OFS (Output File Separator) also in awk to design the o/p....
Say abc.txt is a file contains below data..

$cat abc.txt
ccc#bbb#111
Nnn#hgh#ghs#hhsh

$awk -F'#' '{print $1 $2}' abc.txt
ccc bbb
Nnn hgh

Below is the example with OFS where output is formatted

$ awk -F'#' 'BEGIN{OFS="-"}{print $1,$2}' abc.txt
ccc-bbb
Nnn-hgh

Specifying a  , between columns is mandatory. OFS will be ignored in case " ," is not specified.