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
pattern matching over more lines trek Shell Programming and Scripting 3 04-22-2008 06:37 AM
Script to find file name for non matching pattern sujoy101 Shell Programming and Scripting 5 03-31-2008 09:10 AM
Reading lines in a file matching a pattern torenji Shell Programming and Scripting 4 10-25-2007 04:15 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM
getting file words as pattern matching arunkumar_mca High Level Programming 5 05-31-2005 03:28 AM

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 04-09-2009
digitalrg's Avatar
digitalrg digitalrg is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 26
Quote:
Originally Posted by Franklin52 View Post
With awk:

Code:
awk '/total/{c=10;next}c-->0' file
Regards

Thanks Franklin52
Sorry for the streching the thread.. as iam new bie in the Unix....

with the above command it starts printing 10 lines below the line with total, so if i wish to print that line with total also what needs to be done.......
Regards
  #2 (permalink)  
Old 04-10-2009
digitalrg's Avatar
digitalrg digitalrg is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 26
Hi Franklin52
Sorry to extend again... if i want to introduce a line of
=============================================
after every 10 lines of pattern total what shall i do ?

Thanks
  #3 (permalink)  
Old 04-10-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Quote:
Originally Posted by digitalrg View Post
Hi Franklin52
Sorry to extend again... if i want to introduce a line of
=============================================
after every 10 lines of pattern total what shall i do ?

Thanks
Something like this?

Code:
awk '/total/{c=11}c-->0{print;if(c==0){print "======"}}' file
  #4 (permalink)  
Old 04-10-2009
digitalrg's Avatar
digitalrg digitalrg is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 26
Thanks Franklin this didnt work.. no difference.. in the output
  #5 (permalink)  
Old 04-10-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Quote:
Originally Posted by digitalrg View Post
Thanks Franklin this didnt work.. no difference.. in the output
It works fine on my system, but maybe not with an earlier version of awk, try this:

Code:
awk '/total/{c=11}c>0{c--;print;if(c==0){print "======"}}' file
Regards
  #6 (permalink)  
Old 04-13-2009
digitalrg's Avatar
digitalrg digitalrg is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 26
Great that works
Thanks alot Franklin
Have a nice time
  #7 (permalink)  
Old 04-13-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
brute force in ksh works juuuuust fine:

Code:

pattern=droberts

cat /etc/passwd |
while read line ; do

  lines[9]=${lines[8]}
  lines[8]=${lines[7]}
  lines[7]=${lines[6]}

  lines[6]=${lines[5]}
  lines[5]=${lines[4]}
  lines[4]=${lines[3]}

  lines[3]=${lines[2]}
  lines[2]=${lines[1]}
  lines[1]=${lines[0]}
  lines[0]=$line

  if [[ $line = *${pattern}* ]]; then

    for x in 9 8 7 6 5 4 3 2 1 0 ; do

      print "${lines[x]}"

    done

  fi

done
Closed Thread

Bookmarks

Tags
linux, perl, perl shift, shift, shift perl

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 08:30 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