I am working on this awk tutorial here.
$ head file
Name,Number,Letter
Unix,10,A
Linux,30,B
Solaris,40,C
Fedora,20,D
Ubuntu,50,E
this command inserts a new column after the last column. But i do not want to add to the header, how do I do this? I will also, after this, want to add a header name after.
$ awk -F, '{$(NF+1)=++i;}1' OFS=, file
Name,Number,Letter,1
Unix,10,A ,2
Linux,30,B ,3
Solaris,40,C ,4
Fedora,20,D ,5
Ubuntu,50,E,6
stb(strip trailing blanks) which I use to ensure no trailing blanks. Invim, you could use:g/[ ^I][ ^I]*$/s///(where the^Iis a tab) to eliminate trailing blanks and tabs. At the office,vimis set up to display ghastly yellow when there's a trailing blank or tab on a line in a source file. Etc. Basically, trailing blanks and tabs are untidy; avoid them when you can.ivariable is redundant sinceNRprovides a count of lines. Setting FS and OFS to the same value in 2 different places is a terrible idea and that's not a reason to set vars in the file list so I'd treat anything else in that tutorial with a lot of suspicion. Useawk 'BEGIN{FS=OFS=","} .. ' fileinstead ofawk -F, '...' OFS="," fileand get the book Effective Awk Programming, Third Edition, by Arnold Robbins.