How to append the output in a new column?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to append the output in a new column?
# 1  
Old 06-03-2017
How to append the output in a new column?

Code:
input1
john 20
bob 30

Code:
input2
john 60
bob 100

Code:
cat input1 >> output
cat input2 >> output

ouput
Code:
john 20
bob 30
john 60
bob 100

desired output
Code:
input1 input1 input2 input2
john 20 john 60
bob 30 bob 100

# 2  
Old 06-03-2017
Try
Code:
join file[12]
john 20 60
bob 30 100

or
Code:
paste file[12]
john 20    john 60
bob 30    bob 100

This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-03-2017
Hello quincyjones,

Could you please try following and let me know if this helps you.
Code:
awk 'FNR==NR{A[FNR]=$0;next} {printf("%s\n",FNR==1?A[FNR] FS A[FNR] FS $0 FS $0:A[FNR] FS $0)}'  Input_file1   Input_file2

Thanks,
R. Singh
# 4  
Old 06-03-2017
Quote:
Originally Posted by quincyjones
Code:
input1
john 20
bob 30

Code:
input2
john 60
bob 100

Code:
cat input1 >> output
cat input2 >> output

ouput
Code:
john 20
bob 30
john 60
bob 100

desired output
Code:
input1 input1 input2 input2
john 20 john 60
bob 30 bob 100

Are you sure you want input1 input1 input2 input2? In the files there's only one record of each which it would be:
Code:
input1 input2
john 20 john 60
bob 30 bob 100

If this is the case paste is the strongest contender, but with space delimiter setup instead of a tab as RudiC's example.
Code:
paste -d' ' input{1,2}

Output:
Code:
input1 input2
john 20 john 60
bob 30 bob 100

I do not consider join an option, here, since lines must be sorted and there must be a common field in each line.

Last edited by Aia; 06-03-2017 at 06:07 PM.. Reason: Explain about join
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

3. Shell Programming and Scripting

awk to Sum columns when other column has duplicates and append one column value to another with Care

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (1 Reply)
Discussion started by: as7951
1 Replies

4. Shell Programming and Scripting

Matching column value from 2 different file using awk and append value from different column

Hi, I have 2 csv files. a.csv HUAWEI,20LMG011_DEKET_1296_RTN-980_IDU-1-11-ISV3-1(to LAMONGAN_M),East_Java,20LMG011_DEKET_1296_RTN-980_IDU-1,20LMG011,20LMG 027_1287_LAMONGAN_RTN980_IDU1,20LMG027,1+1(HSB),195.675,20LMG011-20LMG027,99.9995,202.6952012... (7 Replies)
Discussion started by: tententen
7 Replies

5. Shell Programming and Scripting

Matching column then append to existing File as new column

Good evening I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this. I have file called file1 and file2. I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Discussion started by: mychbears
4 Replies

6. Shell Programming and Scripting

Append sha256 column to a file

Hi, My file looks like below: 1 abc@xyz.com 2 klm@klm.com There are two fields separated by tab. i want to append a third field which will be the sha256 hash of the email address field. Anyone have any solution? Note: I have already tried with while read line .... but the... (1 Reply)
Discussion started by: Mihir Ray
1 Replies

7. UNIX for Dummies Questions & Answers

append a column by concatenating other columns

Hi In a tab delimited file how can I add a column that have values concatenated from all columns. For example input.txt test1 test2 test3 zz2 mm uu pp3 yy kk ss2 tt ll zz3 mm uu pp23 yy kk ss3 tt ll 11e 22 44 33c 22 99 output.txt test1 test2 test3 reslt (6 Replies)
Discussion started by: mary271
6 Replies

8. Shell Programming and Scripting

Append a new column in a file

Hi all, I need to append 'ls --' command output as a new column in a existing file. for example, when i do ls -- i will get the below, aaa_import.csv bbb_import.csv ccc_import.csv ddd_import.csv ffff_import.csv i need to cut the aaa, bbb, ccc, ddd and append this a new column... (5 Replies)
Discussion started by: baskivs
5 Replies

9. Shell Programming and Scripting

sed append in first column

hi, anyone can give a sample command on sed. the text file date list belows; test.txt "a","bbb",123 "b","ccc",234 "c","eee",456 output i need to add these word "xxx" "xxx","a","bbb",123 "xxx","b","ccc",234 "xxx" ,"c","eee",456 thanks in advance, FSP (4 Replies)
Discussion started by: fspalero
4 Replies

10. Shell Programming and Scripting

Append the data to first column

Hi, The below is the content of the file. 008.03.50.21|ID4|0015a3f01cf3 008.04.20.16|ID3|0015a3f02337 008.04.20.17|ID4_1xVoice|00131180d80e 008.04.20.03|ID3_1xVoice|0015a3694125 008.04.30.05|ID3_1xVoice|0015a3f038af 008.06.30.17|ID3_1xVoice|00159660d454... (2 Replies)
Discussion started by: ravi_rn
2 Replies
Login or Register to Ask a Question

Featured Tech Videos