I have file with 20 fields and its pipe delimiter. I need to remove the 18th field along with pipe delimiter that seperates 17th and 18th field. In turn that means i want to make it now a file with only 19 fields. Can some body let me know how ican remove the 18th field from the whole file?
awk '$18 = $19 FS $20 {
NF = 18
}
1' FS="|" OFS="|"
For this use nawk on Solaris.
Radolv,
can you please explain the code if u dont mind?
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).
Of, course,
you can write it like this,
if you wish:
awk '{
for (i = 1; i <= NF; i++) {
if (i != 18) {
printf (i > 1) ? ("|" ($i)) : $i
}
}
print ""
}' FS="|" filename
based on radoulov's code
awk -F \| '{ $17 = $17 FS $19 FS $20; NF=17 }1' OFS="|" t1