I have a csv file with following details :
Userid,First Name,Last Name
jaina24,Aayush,Jain
my requirement is to add a new column in the existing file like this :
Userid,Email Address,First Name,Last Name
jaina24,jaina24@xyz.com,Aayush, Jain
2nd column should copy value from first column and then append @xyz.com to it.
NR==1, OFS=","
? And i t seems NR>2 should be NR>=2, or NR>1 – rowboat Jul 07 '21 at 13:53I am once again slightly confused as to how the code is printing only a header. Could you possible expand your statement? Thanks
– sseLtaH Jul 07 '21 at 13:54NR==1
Means only line 1 and OFS returns the field seperators to,
Without it, it has spaces as the delimiter. As there is no input in line 2 in this example, there is no need for>=
What is the difference with announcing Nr>=2, NR>1 or even NR!=1? – sseLtaH Jul 07 '21 at 13:59Copy my input file and run the command without OFS and you will see the results and why it is needed.
– sseLtaH Jul 07 '21 at 14:50NR==1, OFS=","
means print range of line start from thr first line upto when conditionOFS=","
evaluates to true which that evaluates to true immediately at first line and then actions will be executed, but yes it sets the OFS to a comma too, so that action is only executed when it's the first line. – αғsнιη Jul 07 '21 at 15:02