Select multiple column from multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Select multiple column from multiple files
# 1  
Old 03-17-2015
Select multiple column from multiple files

Hi Friends,

Code:
[pani@vfaul059 ~]$ cat test1.txt
emeka:1438
shelley:1439
dmeyer:1440
kurtarn:1441
abdul:1442

[pani@test.txt ~]$ cat test2.txt
1:a
2:b
3:c
4:d
 
[pani@test.txt ~]$ cat test3.txt
cat:dog:bat
man:hot:cold

Code:
O/P : cat test3.txt
dog:bat:a:1438
hot:cold:b:1439
:c:1440
:d:1441
::1442

Regards,
jewel

Last edited by joeyg; 03-17-2015 at 03:49 PM.. Reason: Please wrap scripts/commands and data inside CodeTags
# 2  
Old 03-17-2015
Tryign to understand...

Looks like combining:
fields 2 & 3 from test3 with
field 2 from test2 with
field 2 from test2

Is that correct?
# 3  
Old 03-17-2015
O/P:
--------------------------------------
fisrst column of 3rd file:3rd column of 3rd file:2nd colun of 2nd file:2nd column of 1st file
# 4  
Old 03-17-2015
try:
Code:
paste test3.txt test2.txt test1.txt |
awk '{for(i=1; i<=NF; i++) sub(/[^:]*:/,x,$i)}1' FS='\t' OFS=:

Code:
dog:bat:a:1438
hot:cold:b:1439
:c:1440
:d:1441
::1442

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 03-18-2015
Really your are champ

---------- Post updated 03-18-15 at 03:35 AM ---------- Previous update was 03-17-15 at 01:16 PM ----------

Code:
[pani@testenv ~]# paste test1.txt test2.txt test3.txt | awk '{for(i=1; i<=NF; i++) sub(/[^:]*:/,x,$i)}1' FS='\t' OFS=:

1438:a:dog:bat
1439:b:hot:cold
1440:c:
1441:d:
1442::

Small correction in O/P :

Code:
1438:a:dog:bat
1439:b:hot:cold
1440:c::
1441:d::
1442:::

---------- Post updated at 05:28 AM ---------- Previous update was at 03:35 AM ----------

Hi Friends,
Need your help to fix.

Code:
[pani@testenv ~]# paste test1.txt test2.txt test3.txt | awk '{for(i=1; i<=NF; i++) sub(/[^:]*:/,x,$i)}1' FS='\t' OFS=:

1438:a:dog:bat
1439:b:hot:cold
1440:c:
1441:d:
1442::



Small correction in O/P :

Code:
1438:a:dog:bat
1439:b:hot:cold
1440:c::
1441:d::
1442:::

Moderator's Comments:
Mod Comment Please use CODE tags as has been requested so many times. Moderators have better things to do than edit all of your posts for you.

Last edited by Don Cragun; 03-18-2015 at 08:54 AM.. Reason: ADD CODE tags again!
# 6  
Old 03-18-2015
For exactly this special case, try
Code:
paste file1 file2 file3 | awk '!$NF{$NF="::"} {for(i=1; i<=5; i++) sub(/[^:]*:/,x,$i)}1' FS='\t' OFS=:
1438:a:dog:bat
1439:b:hot:cold
1440:c::
1441:d::
1442:::

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. Shell Programming and Scripting

Shell Scripting - Select multiple files from numbered list

I am trying to have the user select two files from a numbered list which will eventually be turned into a variable then combined. This is probably something simple and stupid that I am doing. clear echo "Please Select the Show interface status file" select FILE1 in *; echo "Please Select the... (3 Replies)
Discussion started by: dis0wned
3 Replies

3. Shell Programming and Scripting

Help with column delete from multiple files

sample .csv files with 7 columns.I want to delete the last column from each of the below files but retain their file names (1_ContractDocuments.csv,2_ContractDocuments.csv etc.) There can be more files like 3_ContractDocuments.csv , 4_ContractDocuments.csv . Can you please help source .csv... (5 Replies)
Discussion started by: paul1234
5 Replies

4. Shell Programming and Scripting

Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All, I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row). I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I... (3 Replies)
Discussion started by: hkrishnan91
3 Replies

5. Shell Programming and Scripting

Concatenate select lines from multiple files

I have about 6000 files of the following format (three simplified examples shown; actual files have variable numbers of columns, but the same number of lines). I would like to concatenate the ID (*Loc*) and data lines, but not the others, as shown below. The result would be one large file (or... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. UNIX for Dummies Questions & Answers

Grep from multiple files by column name

I have 40 files with varying number of columns They however do have identical column names for the overlapping columns I would like to grep some info from these specific colums e.g file1 id beta se direction N 2 .5 .01 + 1000 5 -.6 .02 - 2000 file2 id ... (6 Replies)
Discussion started by: MFAB
6 Replies

7. Shell Programming and Scripting

Column extraction from multiple files to multiple files

I have roughly ~30 .txt files in a directory which all have unique names. These files all contain text arranged in columns separated by whitespace (example file: [#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS TIDE #yr mo dy hr mn degT m/s m/s m sec ... (5 Replies)
Discussion started by: aozgaa
5 Replies

8. Shell Programming and Scripting

Average of a column in multiple files

I have several sequential files with name stat.1000, stat.1001....to stat.1020 with a format like this 0.01 1 3822 4.97379915032e-14 4.96982253992e-09 0 0.01 3822 1 4.97379915032e-14 4.96982253992e-09 0 0.01 2 502 0.00993165137406 993.165137406 0 0.01 502 2 0.00993165137406 993.165137406 0... (6 Replies)
Discussion started by: kayak
6 Replies

9. UNIX for Advanced & Expert Users

merge two column multiple files into one

Hi I have multiple files each with two columns and I need to combine all those file into a tab delimited file. (multiple entry with same name separated by a comma) The content of the files are as follows: --- file1.txt: name var1 aaa xx aaa gg bbb yy ddd zz --- file2.txt ... (8 Replies)
Discussion started by: mary271
8 Replies

10. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies
Login or Register to Ask a Question