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
Printing out pattern in line FK_Daemon Shell Programming and Scripting 3 11-23-2007 01:27 PM
Printing a Line from a file Nysif Steve UNIX for Dummies Questions & Answers 4 08-31-2007 04:58 AM
printing a line number using awk rjsha1 Shell Programming and Scripting 3 09-01-2006 06:25 AM
Creating a line for printing jhansrod Shell Programming and Scripting 3 06-17-2005 02:38 AM
Printing line numbers MizzGail UNIX for Dummies Questions & Answers 2 07-25-2002 01:18 PM

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

Join Date: Jan 2008
Posts: 2
printing the next line too??

Hi, I'm trying to get awk to print every line ending with a colon along with the next line. I have a file like:


Blah Blah a bunch of words, the money things are as follows:
Spokane 340,087, 000 3.24500% January 23, 2008


does anyone have any advice on this matter? I'm a bit stumped...

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
I forgot to mention that I only want to print the next line if it contains numbers.

Thanks again.
Reply With Quote
  #3  
Old 01-30-2008
Registered User
 

Join Date: Jun 2007
Location: Beijing China
Posts: 495
awk

Hi
Try follow code:

input:
Code:
This is the first line
This is the second line:
This is the third line
This is the forth line:
This is the fifth line
This is the last line
output:
Code:
This is the second line:
This is the third line
This is the forth line:
This is the fifth line
code:
Code:
nawk '
/:$/{
print
getline
print
}' filename
Reply With Quote
  #4  
Old 01-30-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
awk '/:$/{f=1;print;next}f{print;exit}' file
Reply With Quote
  #5  
Old 01-30-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 146
A SED version of the same

Code:
$ sed -n '/:$/{p;n;p;}' lines.out
//Jadu
Reply With Quote
  #6  
Old 01-31-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
Quote:
Originally Posted by jaduks View Post
A SED version of the same
Code:
$ sed -n '/:$/{p;n;p;}' lines.out
//Jadu
or better yet:
Code:
sed -n '/:$/ {N; /[0-9]/ p;}' file
Reply With Quote
  #7  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
I think the second line should be printed if it contains a digit, not the every second line

eg
cat filename


one two three:
1 2 3
four five six
4 5 6


the o/p should be

one two three:
1 2 3
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
nawk, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:55 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