Add columns in the begin of the file

Hello Guys

I need your kind help to solve the below issue

I have an Flat file
Format like

 
CONCAT_KEY|FCTR_LVL_CD|RNWL_NS_CD|RTG_PLN_YR_CD
0000000000000010006100001001500005020071001|0|1|61
0000000000000010006100001003000010020071001|0|1|61

I want to add two column with default values and the o/p should be

 
 
DATA_ACQ_CYC_CNTL_ID|DATA_ACQ_CYC_CNTL_SNPSHT_DT|CONCAT_KEY|FCTR_LVL_CD|RNWL_NS_CD|RTG_PLN_YR_CD
1783579|090511|0000000000000010006100001001500005020071001|0|1|61
1783579|090511|0000000000000010006100001003000010020071001|0|1|61

So I want to add column DATA_ACQ_CYC_CNTL_ID and DATA_ACQ_CYC_CNTL_SNPSHT_DT at the begining of file with default value here those are 1783579 and 090511 but it can change

sed '
1   s/^/DATA_ACQ_CYC_CNTL_ID|DATA_ACQ_CYC_CNTL_SNPSHT_DT|/
2,$ s/^/1783579|090511|/
' INPUTFILE
1 Like

Hi Yazu
Thanks a lot for your reply

But the change is reflecting for first line
The header is coming and one record .The second record is missing.

May be its because the original file has two records so when its appending the header its truncating the last line

Is there any workaround for this

Thanks again for finding time to help me

awk '{print (NR>1)?"1783579|090511|" $0:"DATA_ACQ_CYC_CNTL_ID|DATA_ACQ_CYC_CNTL_SNPSHT_DT|" $0}' infile
1 Like