I would like to add a new column to the end of a csv file and populating the column with values. I have used the following codes and it ends up showing new blank lines in between each record. Please let me know how to avoid these newly added blank lines.
awk -F "," 'NR == 1 {$5="MonthYear"}{ if (NR>1){split($2,a,"[/ ]");$5=a[1]"/"a[3]}}1' RS='\r' OFS="," Test.csv > Test1.csv
tried with both RS='\n' and RS='\r\n' and still get the same result
Input file - Test.csv
Id Day UserId ItemId
1 12/1/17 0:03 2323 tv
2 12/14/17 7:10 4546 frr
3 1/22/18 14:11 2421 fdf
4 2/16/18 13:36 4545 dfdf
5 3/5/18 10:47 1232 dfsdf
Actual output file - Test1.csv
Id Day UserId ItemId MonthYear
1 12/1/17 0:03 2323 tv 12/17
2 12/14/17 7:10 4546 frr 12/17
3 1/22/18 14:11 2421 fdf 1/18
4 2/16/18 13:36 4545 dfdf 2/18
5 3/5/18 10:47 1232 dfsdf 3/18
Expected Output - csv
Id Day UserId ItemId MonthYear
1 12/1/17 0:03 2323 tv 12/17
2 12/14/17 7:10 4546 frr 12/17
3 1/22/18 14:11 2421 fdf 1/18
4 2/16/18 13:36 4545 dfdf 2/18
5 3/5/18 10:47 1232 dfsdf 3/18
Without RS, the output is jumbled up like this:
,MonthYearrId,ItemId
,12/17/17 0:03,2323,tv
,12/174/17 7:10,4546,frr
,1/182/18 14:11,2421,fdf
,2/186/18 13:36,4545,dfdf
5,3/5/18 10:47,1232,dfsdf,3/18
RSwhich is the record seperator. What you want isFSwhich is the field separator.