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
ccc#bbb#111
Nnn#hgh#ghs#hhsh
$awk -F'#' '{print $1 $2}' abc.txt
ccc bbb
Nnn hgh
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
Nnn-hgh
Specifying a , between columns is mandatory. OFS will be ignored in case " ," is not specified.
No comments:
Post a Comment