How to parse 2 files simultaneously


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to parse 2 files simultaneously
# 1  
Old 04-12-2007
How to parse 2 files simultaneously

Say I have 2 files of 2 rows of 3 columns each

file1:

cat catdata1 catdata2
dog dogdata1 dogdata2

file2:

cat catdata3 catdata4
dog dogdata3 dogdata4

and I need to combine both files so that is appears like:

cat catdata1 catdata2 catdata3 catdata4
dog dogdata1 dogdata2 dogdata3 dogdata4

How would I do that? I need the power of awk, but I can't get it to work with 2 files simultaneously.
# 2  
Old 04-12-2007
Code:
join file1 file2

# 3  
Old 04-12-2007
Thanks Reborg,

The join command doesn't seem to work when the join field is a number or date though.

ie.
file1:
2007/04/04 Joey
file2:
2007/04/04 Tabris

join file1 file2
<nothing comes out>
# 4  
Old 04-12-2007
That is strange. I get as I expect:

Code:
2007/04/04 Joey Tabris

What does "uname -a" look like on your machine?
# 5  
Old 04-12-2007
SunOS phxitetl01 5.8 Generic_117350-28 sun4u sparc SUNW,Netra-T12

Actually now that I've tried the example that I've given it does work.

Here's one that doesn't though

file1:

2007/04/04 Joey
john jim

file2:

albert martha
2007/04/04 Jimmy

I don't get it. Is there any way I can look into the tokens that the utility is parsing?
# 6  
Old 04-12-2007
In this case what would the expected output be. When asking questions about data processing you need to give a full example of input(s) and expect output.
# 7  
Old 04-12-2007
Quote:
Originally Posted by reborg
In this case what would the expected output be. When asking questions about data processing you need to give a full example of input(s) and expect output.
I type in
join file1 file2

I would expect the output to be:

2007/04/04 Joey Jimmy
or
2007/04/04 Jimmy Joey
doesn't matter which.

Nothing shows up instead

How do I specify a space as a delimeter.

Like join -t " "
or do I have to use some ascii character like join -t "\0000"
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to delete files on two remote servers simultaneously?

dear all, i'm preparing a script which can do these actions : 1. stop remove server's certain service 2. clean the files on remote servers simultaneously (because lots of files need to be deleted) 3. after files/logs are removed, restart the service again i'm stuck on how to clean remote... (4 Replies)
Discussion started by: tiger2000
4 Replies

2. Shell Programming and Scripting

Handling 2 files simultaneously with awk

Hello, Is it possible to handle data from two different files at once in awk (latest version and platform is Fedora). I found on the net that we cannot nest awk. My requirement is that I have two similar files : File 1: Name: abc Val = 58 Name: cdf Val = 1; .................. File... (7 Replies)
Discussion started by: fifteate
7 Replies

3. Shell Programming and Scripting

Parse 2 or more files into one.

Hi, I have a really simple question...I think. I want to be able to parse two or more files into one by reading the first record from each file into new file then go back to the first file and start reading the second record in from each file into new file and so on. I am new to using awk and am... (5 Replies)
Discussion started by: qray2011
5 Replies

4. UNIX for Dummies Questions & Answers

can I create symbolic links for multiple files simultaneously

Does anybody know how to make symbolic links for multiple files simultaneously? Often times I need make symbolic links for multiple files with some common pattern (just like "*.jpg"). Is there a way to avoid making symbolic link for each of them one by one... Thank you! (6 Replies)
Discussion started by: danieladna
6 Replies

5. Shell Programming and Scripting

Looping through 2 files simultaneously

Hi all, I'm having a problem with a script which should ultimately provide a filename by reading a value from file1 and file2 then join together. I'm planning to use a loop/ loops to get the values out of both files and create a single string unfortunately the code currently treats the second... (7 Replies)
Discussion started by: chris01010
7 Replies

6. Shell Programming and Scripting

[bash] Parse files

Hi I've 2 folder A and B, they have files with the same name but different content. I mean A contain---------> aa.txt, bb.txt, cc.txt B contain---------> aa.txt, bb.txt, cc.txt but aa.txt in A has different content from aa.txt in B. I'd like to parse the homonyms files in... (7 Replies)
Discussion started by: Dedalus
7 Replies

7. Shell Programming and Scripting

renaming multiple files simultaneously

Hi , I have a large no of files which all end in .asp.htm extension . But for proper navigation between the pages I need to rename all those files as .asp only . How can it be done ? (4 Replies)
Discussion started by: nshailesh
4 Replies

8. Shell Programming and Scripting

Tailing 2 or more log files simultaneously PERL

Hi, I am having issue where I have to tail 3 log files continuously (forever) and while I am reading the files , parse them and shove the data into DB. I can do this with one file totally fine but how can I read 3 files at the same time? I am not really looking for code (but would be nice) but... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

9. Shell Programming and Scripting

simultaneously create three empty files?

I can't get touch to simultaneously create three empty files file1, file2, file3. I tried:$ touch filebut all I got was one file:$ fileWhat did I do wrong? (4 Replies)
Discussion started by: na5m
4 Replies
Login or Register to Ask a Question