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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2009
goswami.c goswami.c is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 2
help with sed

i have two files

file 1 containing :


Code:
aaa
bbb
ccc
.
.
.
zzz

file 2 containing


Code:
111
222
333
111
222
333
.
.
.

what i want in the end is this in file 3


Code:
111
222
aaa
111
222
bbb
333
111
222
ccc
.
.
.

i know i can do this with sed and i have done it for one string to be inserted after a particular pattern but i am able to do the action above
may be its possible with a loop but i have been trying for some time cant arrive

please help

Last edited by vgersh99; 08-21-2009 at 09:06 AM.. Reason: code tags, PLEASE!
  #2 (permalink)  
Old 08-21-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
  #3 (permalink)  
Old 08-21-2009
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
Not sure I get your criteria totally, from your expected output:


Code:
111 line 1 from file2
222 line 2 from file 2
aaa line 1 from file 1
111 line 4 from file2  ...   what happened to line 3 from file 2
222 line 5 from file2
bbb line 2 from file 1
333 line 6? from file2
111 line 7 from file2
222 line  8 from file 2
ccc line 3 from file 1

Do you just want to get two lines from file2, followed by one line from file 1 ?


Code:
cat file2 | paste - - file1| tr "\t" "\n"

Or is there more complex criteria ?

HTH
  #4 (permalink)  
Old 08-21-2009
goswami.c goswami.c is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 2
actually Tyatalus

i have file 1 containing different strings each in a differnt line and what i want to do is insert these strings before a particular pattern in file 2

eg file 1 may contain

AAA
BBB
and so on there are 201 entries exactly

now i want to insert AAA after pattern XXX in file 2 then BBB after the next occurence of pattern XXX and so on
  #5 (permalink)  
Old 08-21-2009
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
ah. in that case I think you want:


Code:
#  nawk '/222/{print;getline < "file1"}{print}' file2

HTH
Reply

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 07:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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