Friday, February 8, 2008

Trip or chop a particular field from input

In this post you will learn now you can trim or chop-off a particular field (column) from the input text

To delete the 19th field from a 20 field text delimited by a pipe

awk '$18 = $19 FS $20 {
NF = 18
}
1' FS="|" OFS="|"


Assign the value $19 FS $20 to field 18,
so filed 18 becomes field 19 | field 20.
Then (this works with some awks like GNU Awk and New Awk)
make the record 18 fields (NF = 18, number of fields is 18).


Created and explained by radoulov

No comments: