LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-10-2004, 12:45 PM   #1
f0rmula
Member
 
Registered: Dec 2003
Posts: 72

Rep: Reputation: 15
shell scripting.. where to start?


never written a script before, but now im finding the need for them...

here goes..

i want to write a shell script to take interleave the lines of a file with another..

i.e.

---------------------

file1.txt:

1
2
3

-------------------

file2.txt

10
11
12

--------------------

to produce another file..

1
10
11
12
2
10
11
12
3
10
11
12

-----------------------

where would i start on how to learn to do this, or has anyone got a simple solution or idea that might help

thanks in advance

james
 
Old 02-10-2004, 12:53 PM   #2
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
cat file1 | while read a; do echo $a; cat file2 | while read b; do echo $b; done; done
 
Old 02-10-2004, 01:24 PM   #3
lone_nut
Member
 
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
Or save a loop and simply type:
cat file1 | while read a; do echo $a;cat file2;done

Happy hacking
 
Old 02-11-2004, 05:39 AM   #4
f0rmula
Member
 
Registered: Dec 2003
Posts: 72

Original Poster
Rep: Reputation: 15
blinding.. thankyou

ill have a go and let you know..

james
 
Old 02-11-2004, 06:16 AM   #5
f0rmula
Member
 
Registered: Dec 2003
Posts: 72

Original Poster
Rep: Reputation: 15
first one works beutifully, second one leave the lines from the first file, tagged onto the ends of the lines of the second file..

is there any way i can insert characters into the sequence? i.e. insert tabs before the lines of the second file to lay them out tree style..

james
 
Old 02-11-2004, 10:24 AM   #6
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
Or save a loop and simply type:
cat file1 | while read a; do echo $a;cat file2;done"

that's even better!
_____________________________

"first one works beutifully, second one leave the lines from the first file, tagged onto the ends of the lines of the second file.."

second one should work also, sounds like you don't have a newline at the end of the second file
_____________________________

"is there any way i can insert characters into the sequence? i.e. insert tabs before the lines of the second file to lay them out tree style.."

cat file1 | while read a; do echo $a; cat file2 | sed 's/^/\t/'; done
 
  


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
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM
shell scripting emailssent Programming 4 03-16-2005 11:39 PM
shell scripting rch Programming 3 06-07-2003 05:10 AM
Shell Scripting, I think... AMDPwred Linux - General 1 04-06-2002 01:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:31 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration