0
How can I add a new column to a tab delimited file, at the end of the file, containing the same values for each row.
For example:
infile.txt
Name Age Address Sex
X 12 adrs1 M
Y 15 adrs2 F
Z 10 adrs3 M
I want to add another coloumn 'School' containing same values'st.xaviers ' for each row
outfile.txt
Name Age Address Sex School
X 12 adrs1 M st.xaviers
Y 15 adrs2 F st.xaviers
Z 10 adrs3 M st.xaviers
I have tried awk '{print $0, "School"}
to add the column. How can I add the 'st.xaviers' to each row in column "School" ?
Now, if this is part of shell script, and I have a predefined variable School=st.xaviers.
How Can I add $School
values to the Column 'School' in outfile.txt
Thanks a lot. It worked. How can include the {print $0 "\tst.xaviers"}' argument from $school within a shell script, example: l#!/usr/bin/bash infile=infile.txt outfile=outfile.txt school=st.xaviers
#I do some extra operations with the files #and finally would like to awk '$1=="Name" { print $0 "\tSchool"; next}; $1 {print $0 "\tst.xaviers"}' $infile $outfile – panbar – 2016-03-17T14:58:22.160
I get it, so you want school to be dynamic. Answer edited. – Gombai Sándor – 2016-03-17T15:07:18.693