LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 10: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, 10: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, 11:09 AM   #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, 11:17 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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 11:18 AM.
 
Old 07-14-2008, 11:37 AM   #5
visitnag
Member
 
Registered: Mar 2008
Posts: 147

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:50 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
Open Source Consulting | Domain Registration