Append a specific keyword in a text file into a new column

All,

I have some sample text file(.csv) in the below format. In my actual file there are at least 100K rows.

date 03/25/2016
A,B,C
D,E,F
date 03/26/2016
1,2,3
4,5,6
date 03/27/2016
6,4,3
4,5,6

I require the following output where in the date appeared at different locations need to be tranaformed into first column of the file.

03/25/2016,A,B,C
03/25/2016,D,E,F
03/26/2016,1,2,3
03/26/2016,4,5,6
03/27/2016,6,4,3
03/27/2016,4,5,6

Currently I am manually doing this process in Excel but I am finding it as a very tedious process.

Thanks in advance

Can be done in EXCEL pretty simple and fast. However, try

awk '/^date/ {T = $2; next} {print T, $0}' OFS="," file1
03/25/2016,A,B,C
03/25/2016,D,E,F
03/26/2016,1,2,3
03/26/2016,4,5,6
03/27/2016,6,4,3
03/27/2016,4,5,6
1 Like
perl -nle 'm{((\d+/){2}\d+)} and $d=$1 or print "$d,$_"' ks_reddy.csv
03/25/2016,A,B,C
03/25/2016,D,E,F
03/26/2016,1,2,3
03/26/2016,4,5,6
03/27/2016,6,4,3
03/27/2016,4,5,6
1 Like

Thanks RudiC and Aia for your prompt replies.