LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-12-2010, 11:12 AM   #1
Gavin Harper
Member
 
Registered: Feb 2010
Location: Finland
Distribution: Slackware
Posts: 169

Rep: Reputation: 24
BASH: Each line of multiple text files gets added to one line


I currently have 3 files with floating point data that I wish to have in a single file with the format:

Code:
F1      F1     F3          Output

a1      b1     c1          a1 b1 c1
a2      b2     c2          a2 b2 c2
a3      b3     c3          a3 b3 c3
a4      b4     c4          a4 b4 c4
I would greatly appreciate any intuition on how to go about this.

Thank you in advance!
 
Old 09-12-2010, 12:02 PM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Code:
#!/bin/bash

{
    while read -u 3 A && read -u 4 B && read -u 5 C; do
        echo "$A $B $C"
    done
} 3<"$1" 4<"$2" 5<"$3"
save it to script.sh then run

Code:
bash script.sh F1 F2 F3 > OUTPUT
 
1 members found this post helpful.
Old 09-12-2010, 12:22 PM   #3
Gavin Harper
Member
 
Registered: Feb 2010
Location: Finland
Distribution: Slackware
Posts: 169

Original Poster
Rep: Reputation: 24
Thank you very very much!

Worked a charm
 
Old 09-12-2010, 07:31 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
paste?
Code:
$ paste file1 file2 file3
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using python to merge two text files line for line simplified Programming 1 07-06-2010 01:09 PM
a little bash help: cat multiple files together except first line? sanimfj Linux - General 3 02-09-2010 04:27 PM
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 12:29 PM
Bash: How to add a line on top of text files guest Programming 12 02-07-2009 06:23 AM
Search values within multiple files line to line Chrizzieej Programming 5 09-26-2008 04:11 PM


All times are GMT -5. The time now is 03:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration