I have a Tab separated file as follows:
A B HM 1 BN 2 I would like to add another column to this file such that this new column becomes the first column of the file as shown below:
New A B 201507 HM 1 201507 BN 2 How can I do this?
Use paste:
paste -d"\t" file1 file2 Where:
-d specifies the dlimiter between the two files (\t is a tabulator).file1 contains the lines you want to prepend.file2 contains the other lines.Edit: Another solution with awk:
awk '{getline l < "file2"; print $0"\t"l} ' file1 Where:
file2 into the variable called l, which is then printed after the line of file1 followed by a tab \t.When file1 would contain:
New 201507 201507 ...and file2 contains:
A B HM 1 BN 2 ...the output would be:
New A B 201507 HM 1 201507 BN 2 awk solution.