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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-31-2008
AndyA AndyA is offline
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
  #2 (permalink)  
Old 01-31-2008
AndyA AndyA is offline
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.
  #3 (permalink)  
Old 01-31-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
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
  #4 (permalink)  
Old 01-31-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,510
Code:
awk '/:$/{f=1;print;next}f{print;exit}' file
  #5 (permalink)  
Old 01-31-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

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

Code:
$ sed -n '/:$/{p;n;p;}' lines.out
//Jadu
  #6 (permalink)  
Old 01-31-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
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
Closed Thread

Bookmarks

Tags
nawk, sed

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 12:49 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