join cols from multi files into one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting join cols from multi files into one file
# 1  
Old 11-19-2003
join cols from multi files into one file

Hi

Fields in Files 1,2,3,4 are pipe"|" separated.

Say I want to grep

col1 from File1
col3 from File2
col4 from File3

and print to File4 in the following order:

col3|col1|col4

what is the best way of doing this?

Thanks
# 2  
Old 11-19-2003
This is untested, so it may have to be tweaked:
Code:
awk -F"|" '{print $1}' < File1 > tmp1
awk -F"|" '{print $3}' < File2 > tmp2
awk -F"|" '{print $4}' < File3 > tmp3

paste -d"|" tmp2 tmp1 tmp3 > File4

# 3  
Old 11-20-2003
MySQL

Thanks oombera

It works!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join files, omit duplicated records from one file

Hello I have 2 files, eg more file1 file2 :::::::::::::: file1 :::::::::::::: 1 fromfile1 2 fromfile1 3 fromfile1 4 fromfile1 5 fromfile1 6 fromfile1 7 fromfile1 :::::::::::::: file2 :::::::::::::: 3 fromfile2 5 fromfile2 (4 Replies)
Discussion started by: CHoggarth
4 Replies

2. Shell Programming and Scripting

Multi column join

Hello folks, having a new problem with an old solution I previously had working, but think i'm missing something here. File1: 900001093|HAMU1|SUDO_ALIAS 100100361|IAM_IDS|SUDO_ALIAS 100100361|AMPF|SUDO_ALIAS File2: ABC123456|Cust1|900001093|myemail@here.com|Jane Smith|Win1|hamu1... (2 Replies)
Discussion started by: dagamier
2 Replies

3. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

4. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

5. Shell Programming and Scripting

Join txt files with diff cols and rows

I am a new user of Unix/Linux, so this question might be a bit simple! I am trying to join two (very large) files that both have different # of cols and rows in each file. I want to keep 'all' rows and 'all' cols from both files in the joint file, and the primary key variables are in the rows.... (1 Reply)
Discussion started by: BNasir
1 Replies

6. Shell Programming and Scripting

Join two files values duplciating first file

Hi all, I am tryin to join two files, duplicating the alues from the first one as many times as the second. File one : 11 211 File two: a b c Result: 11 211 a 11 211 b 11 211 c Any advise will be apreciate. Thanks (3 Replies)
Discussion started by: valigula
3 Replies

7. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

8. Shell Programming and Scripting

sort and split file by 2 cols (1 col after the other)

Dear All, I am a newbie to shell scripting so this one is really over my head. I have a text file with five fields as below: 76576.867188 6232.454102 2.008904 55.000000 3 76576.867188 6232.454102 3.607231 55.000000 4 76576.867188 6232.454102 1.555146 65.000000 3 76576.867188 6232.454102... (19 Replies)
Discussion started by: Ghetz
19 Replies

9. Shell Programming and Scripting

Join 3 files using key column in a mapping file

I'm new of UNIX shell scripting. I'm recently generating a excel report in UNIX(file with delimiter is fine). How should I make a script to do it? 1 file to join comes from output of one UNIX command, the second from another UNIX command, and third from a database query. The key columes of all... (7 Replies)
Discussion started by: bigsmile
7 Replies

10. Shell Programming and Scripting

How to find number of Cols in a file ?

Hi I have a requirement wherein the file is comma separated. Each records seems to have different number of columns, how I can detect like a row index wise, how many columns are present ? Thanks in advance. (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question