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
Grep help flood Shell Programming and Scripting 3 06-06-2008 01:14 AM
Grep Aejaz UNIX for Advanced & Expert Users 3 04-30-2008 07:10 AM
grep dineshr85 Shell Programming and Scripting 1 10-10-2007 04:52 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM

Closed Thread
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 03-16-2004
CKS CKS is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 1
Grep/Sed help?

I'm a UNIX novice and am currently using a grep stmt to search for a pattern and send the matching lines to a new file. But what I really want to do is to append the line after the matching line to the matching line in the new file.

Any ideas?

3/17/04 I am using the Bourne shell.

And the sed line from Ygor works nicely to capture the line after the pattern line, but I still need to incorporate something that will also capture the pattern line itself.

Last edited by CKS; 03-17-2004 at 01:53 PM..
  #2 (permalink)  
Old 03-17-2004
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
  
 

Join Date: May 2002
Location: India
Posts: 295
what shell are you using

Normally I would do

grep "pattern" infiles >> destfiles
  #3 (permalink)  
Old 03-17-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
This quote is from:Handy One-Liners for SED
Quote:
# print the line immediately after a regexp, but not the line
# containing the regexp
sed -n '/regexp/{n;p;}'
  #4 (permalink)  
Old 03-19-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Quote:
3/17/04 I am using the Bourne shell.

And the sed line from Ygor works nicely to capture the line after the pattern line, but I still need to incorporate something that will also capture the pattern line itself.
It's not hard edit the sed script.

Original: sed -n '/regexp/{n;p;}'
Becomes: sed -n '/regexp/{p;n;p;}'

Where: n = next line ; p = print

As an alternative to sed, you could use awk which is easier to understand:

awk '/regexp/{print;getline;print}'
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 11:07 PM.


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