files cross over


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting files cross over
# 1  
Old 10-17-2007
files cross over

I have many files (File 1, File 2, File 3, ...) in same directory.
The format of all these files are same.
What I would like to do is to combine all these files into a single file via cross over.
Example)
>>File 1 look like this.
f1 01 1.0
f1 02 2.0
f1 03 3.0
f1 04 4.0
f1 05 5.0
f1 06 6.0
.
.

>>File 2 look like this
f2 01 21.0
f2 02 22.0
f2 03 23.0
f2 04 24.0
f2 05 25.0
f2 06 26.0
.
.

>>File 3 look like this
f3 01 31.0
f3 02 32.0
f3 03 33.0
f3 04 34.0
f3 05 35.0
f3 06 36.0
.
.

The result should look like this.
f1 1.0 2.0 3.0
f2 21.0 22.0 23.0
f3 31.0 32.0 33.0
f1 4.0 5.0 6.0
f2 24.0 25.0 26.0
f3 34.0 35.0 36.0
.
.

Thanks in advance.
# 2  
Old 10-17-2007
Hi.

You can use command paste for this, but you need to tell it to use a newline (\n) rather than a TAB as a separator.

See man paste, experiment, and follow-up if you run into trouble ... cheers, drl
# 3  
Old 10-18-2007
As drl suggested (this is the lazy way, you could make f1,f2 ... dynamic if you wish, and use parameter expansion instead of cut):

Code:
zsh 4.3.4% fgrep . file*
file1:f1 01 1.0
file1:f1 02 2.0
file1:f1 03 3.0
file1:f1 04 4.0
file1:f1 05 5.0
file1:f1 06 6.0
file2:f2 01 21.0
file2:f2 02 22.0
file2:f2 03 23.0
file2:f2 04 24.0
file2:f2 05 25.0
file2:f2 06 26.0
file3:f3 01 31.0
file3:f3 02 32.0
file3:f3 03 33.0
file3:f3 04 34.0
file3:f3 05 35.0
file3:f3 06 36.0
zsh 4.3.4% paste -d"\n" <(printf "f1 %s %s %s\n" $(cut -f3 -d" " file1))\
<(printf "f2 %s %s %s\n" $(cut -f3 -d" " file2))\
<(printf "f3 %s %s %s\n" $(cut -f3 -d" " file3))
f1 1.0 2.0 3.0
f2 21.0 22.0 23.0
f3 31.0 32.0 33.0
f1 4.0 5.0 6.0
f2 24.0 25.0 26.0
f3 34.0 35.0 36.0

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cross Tab

I need help to do cross tab file input 20160101|ASIA|CHINA|2000 20160101|ASIA|INDIA|3000 20160102|ASIA|CHINA|4000 20160103|ASIA|CHINA|2000 20160103|AFRIKA|ZAMBIA|2000 20160104|ASIA|CHINA|5000 expected output CONTINENT|NATION|20160101|20160102|20160103|20160104... (1 Reply)
Discussion started by: radius
1 Replies

2. Programming

what is a cross compiler

recently i was been to an interview to an automotive company, they have posed me a question that what section of compiler must be changed if the target is changed. ie,if ur compiler is meant for generating executable to a 8051 target what changes do you do to make it flexible to generate the... (2 Replies)
Discussion started by: shyam.sunder91
2 Replies

3. Linux

Cross compile

Hi, I'm cross compiling libelektra to arm from linux system its giving library errors can any one help me? (0 Replies)
Discussion started by: Gautham.P
0 Replies

4. UNIX for Dummies Questions & Answers

Cross complie linux make files onto a windows 7 machine using PGI Cygwin

Hello, I am very unfamiliar with linux/unix (don't even know the difference), but am trying to get some linux software to run on my Windows machine for my research. I have the makefiles for the software, and it is designed to be compiled in the PGI complier, which I also have. When i... (6 Replies)
Discussion started by: roba87
6 Replies

5. Shell Programming and Scripting

awk cross-referencing between two files

I need to make my sloppy, existing code (non awk) more efficient and I seem to be terrible with awk :wall: I've tried around quite a bit, maybe you guys can conjure up a quick solution... file1: 2 SOL 563 2 SOL 565 3 SOL 589 2 SOL 603 1 SOL 612 1 SOL 621... (1 Reply)
Discussion started by: origamisven
1 Replies

6. Shell Programming and Scripting

Cross checking two files

i have two files which contains some fields separated by columns as 03/29/1999 08:48:12 02 172.16.114.50 03/29/1999 09:08:00 480 172.16.112.100 Both of the files do have the same format I want the script which will take two such... (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

7. Post Here to Contact Site Administrators and Moderators

Cross Posting

In regards to this post: https://www.unix.com/showthread.php?s=&threadid=10372 it may be advisable to inform new members about the repercussions of cross-posting. (9 Replies)
Discussion started by: Karma
9 Replies
Login or Register to Ask a Question