The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to insert text in the middle of a file kartikkumar84@g UNIX for Dummies Questions & Answers 6 05-10-2008 11:35 AM
insert text in the middle of a file relle Shell Programming and Scripting 3 03-13-2008 12:37 PM
How to insert the 1st arg into the middle of the file boris Shell Programming and Scripting 4 04-12-2007 09:21 PM
How to insert text into first line of the file and middle of the file? ali hussain Shell Programming and Scripting 3 03-05-2007 02:54 AM
insert text into the middle of a original file mopimp Shell Programming and Scripting 1 03-26-2006 07:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-07-2008
Registered User
 

Join Date: Jul 2007
Posts: 89
Post insert one file into middle of another file

how to insert one file into another file not by concatenating as usual done.
file1
A B
C D
E F

G H
I J

K L

file2
23455
33444
33334
33345


Output shud be
23455
A B
C D
33444
E F
G H
33345
I J
K L
Reply With Quote
Forum Sponsor
  #2  
Old 03-07-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
probably an easier way than this, but it does work :

Code:
#  paste -s -d "\t\n" file1 | paste file2 - | tr "\t" "\n"
23455
A B
C D
33444
E F
G H
33334
I J
K L
33345
Reply With Quote
  #3  
Old 03-07-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
also - can use cat for legibility:

Code:
#  cat file1 | paste - - | paste file2 - | tr "\t" "\n"
does same as 1st ans..
Reply With Quote
  #4  
Old 03-07-2008
Registered User
 

Join Date: Jul 2007
Posts: 89
33334
I J
K L
33345

[/code][/quote]


Thanks.....

Last edited by cdfd123; 03-07-2008 at 05:05 AM. Reason: just thanks
Reply With Quote
  #5  
Old 03-07-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
awk 'FNR==NR{ a[FNR]=$0;next }
{ 
  print $0
  print a[FNR+l]
  l++
  print a[FNR+l]
}
' file file1
output
Code:
# ./test.sh
23455
A B
C D
33444
E F
G H
33334
I J
K L
33345
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0