Need to Insert three extra columns in csv file

Hello Experts,

I got a requirement i have a input file which am getting from different source,Now i want to add extra 3 columns to this file like BASE,ACTUAL and DATE.

Input File Looks like

QUAL	CHGE	 TYP	LAW COM1	COM2
A        1      X     SED   HO    ASE
B        3      Z     CDE   SE     TOE

Ouptut file i need like this

BASE ACTUAL    DATE           QUAL CHGE   TYP LAW  COM1 COM2
PD    DV     09/11/2015         A       1       X  SED   HO    ASE
PD    DV     09/11/2015         B       3       Z  CDE   SE     TOE

Please help me out here,Am new to shell scripting.

Regards,
Ahmed.

Hello ahmed.vaghar,

Welcome to forum, please use code tags in your inputs/codes/samples used in your posts as per forum rules, following may help you in same.
Input_file:

cat change_fields
QUAL    CHGE     TYP    LAW COM1        COM2
A        1      X     SED   HO    ASE
B        3      Z     CDE   SE     TOE

Then following code may help.

awk 'NR==1{$0="BASE ACTUAL    DATE" "\t\t" $0} NR>1{$0="PD    DV     09/11/2015" "\t\t" $0} 1' change_fields

Output will be as follows.

BASE ACTUAL    DATE             QUAL    CHGE     TYP    LAW COM1        COM2
PD    DV     09/11/2015         A        1      X     SED   HO    ASE
PD    DV     09/11/2015         B        3      Z     CDE   SE     TOE

Thanks,
R. Singh

Thank you very much Ravinder for prompt response.

Yes it is working.But my requirement is to write the output in CSV file.I can able to write that in CSV file using this command ">" Is there a way i can write each field in each column of CSV file

Attached the output file which am getting now for your reference.

Thanks Once again.

Regards,
Ahmed.

Your welcome Ahmad. You can use the following command to get output in a .csv file first.

 awk 'NR==1{$0="BASE ACTUAL    DATE" "\t\t" $0} NR>1{$0="PD    DV     09/11/2015" "\t\t" $0} 1' change_fields > sample.csv
 

Now open .csv file and perform following steps.

 Go to Menu's DATA option ---> Select TEXT to Columns option---> Select Delimited option--->Then select  TAB + space --->Give a Next in wizard--->Click DONE
 

Here I am considering that your fields doesn't have space in themselves
else it will segregate them too.

Thanks,
R. Singh

Ravinder,

Thanks again.

Is there a way we can do that using script.

I can't see three columns added to your sample file, I see three words separated by spaces added to your first column.

A .csv file is a text file with columns separated by commas, semicolons or similar, readable immediately by data bases or spread sheets. To achieve this, try

awk '{T=(NR==1)?"BASE;ACTUAL;DATE":"PD;DV;09/11/2015"; $1=$1; printf "%s;%s\n", T, $0} ' OFS=";" file
BASE;ACTUAL;DATE;QUAL;CHGE;TYP;LAW;COM1;COM2
PD;DV;09/11/2015;A;1;X;SED;HO;ASE
PD;DV;09/11/2015;B;3;Z;CDE;SE;TOE

and try to open it with e.g. EXCEL.