The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
insert one file into middle of another file cdfd123 Shell Programming and Scripting 4 03-07-2008 08:13 AM
capturing line from script output and appending to a file wally_welder Shell Programming and Scripting 6 08-31-2007 03:03 AM
How to insert the 1st arg into the middle of the file boris Shell Programming and Scripting 4 04-13-2007 12:21 AM
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 05:54 AM
Reading specific contents from a file and appending it to another file dnicky Shell Programming and Scripting 5 10-04-2005 05:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2007
go4desperado go4desperado is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 7
Question appending to sed output of one file into the middle of file

hi,
i have a file

file1 file2
----------- -----------------
aa bbb ccc 111 1111 1111
ddd eee fff 222 3333 4444
ggg hhh iiii 555 6666 777

i select the portion of file1 as

sed -n '/aa/,/fff/p' file1 ,, this select first two lines of file1,

now i need to append these lines to the middle of file2 ie between line1 and line2

Please help me
  #2 (permalink)  
Old 02-02-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sed -n '/aa/,/fff/p' file1 > tmp
sed '1 r tmp' file2
  #3 (permalink)  
Old 02-02-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
head -1 file2
sed -n '/aa/,/fff/p' file1
tail +2 file2
  #4 (permalink)  
Old 02-02-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Without using temp files

Code:
sed "1a\\
$(sed -n -e "/aa/,/fff/{/fff/ ! s/$/\\\\/;p; }" file1)
" file2
  #5 (permalink)  
Old 02-04-2007
go4desperado go4desperado is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 7
slight modification

hi anbu23
that was a cute answer,,,,
but wat about the scenario, in which i replace any pattern space by some file contents....
  #6 (permalink)  
Old 02-05-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by go4desperado
hi anbu23
that was a cute answer,,,,
but wat about the scenario, in which i replace any pattern space by some file contents....
You can use change command
Code:
sed "1c\\
$(sed -n -e "/aa/,/fff/{/fff/ ! s/$/\\\\/;p; }" file1)
" file2
Replace first line in pattern space by file1 contents
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0