LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-14-2008, 11:53 AM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
using awk...merging two files...lines...one after another...


Hi all,

I have two files and want to create a new file by merging these two files.
like..

lin1......of file1
lin1......of file2
lin2......of file1
lin2......of file2
lin3
..
..
 
Old 07-14-2008, 11:55 AM   #2
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Do you have to use awk? How about cat?

Code:
cat file1 fil2 > file3
 
Old 07-14-2008, 12:09 PM   #3
smoked kipper
Member
 
Registered: May 2008
Location: UK
Distribution: Slackware,Slamd64
Posts: 81

Rep: Reputation: 15
Er, cat doesn't interleave the lines.

How about:

Code:
paste -d'\n' file1 file2 > output
 
Old 07-14-2008, 12:17 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
If you really need awk to accomplish this task, you can parse the first file and explicitly get input from the second file using getline:
Code:
awk '{print; getline < "file2"; print}' file1

Last edited by colucix; 07-14-2008 at 12:18 PM.
 
Old 07-14-2008, 12:37 PM   #5
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Thank you all..
 
  


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
Delete lines using awk kkjegan Programming 13 09-11-2007 08:36 PM
AWK - why fields go to seperate lines? korhan Linux - Newbie 2 03-01-2007 04:21 PM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 10:19 AM
awk print lines that doesn't have a pattern huynguye Programming 5 05-04-2006 12:08 PM
awk text that is on several lines homey Programming 2 10-31-2004 10:27 AM


All times are GMT -5. The time now is 08:51 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