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.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Please help on grepping nua7 Shell Programming and Scripting 3 07-15-2008 10:04 AM
grepping around cbeauty Shell Programming and Scripting 9 08-29-2007 02:56 AM
grepping eloquent99 UNIX for Dummies Questions & Answers 5 04-22-2003 11:20 PM
grepping the first 3 characters from a file rachael UNIX for Dummies Questions & Answers 2 10-15-2001 03:33 PM
grepping the first 3 characters from a file g-e-n-o UNIX for Dummies Questions & Answers 2 10-15-2001 07:11 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 04-23-2009
anushree.a anushree.a is offline
Registered User
  
 

Join Date: May 2008
Posts: 87
Grepping characters

Hi friends,
I want your help.
I have a flat file. I want a script to search following pattern in it and once it get that pattern it should grep next 7 characters from it and should keep it in output file output.TXT

Pattern is
RSTD3R0*******

In above example, characters in the place of * (7 characters after pattern RSTD3R0) should be grepped and sent to output.TXT file.

How it can be done?
Kindly help

Regards
Anushree
  #2 (permalink)  
Old 04-23-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
assuming there will always be more than 7 characters after the match string


awk '$0 ~ /RSTD3R0/{match($0,"RSTD3R0");print substr($0,RSTART+RLENGTH,7)}' file


cheers,
Devaraj Takhellambam
  #3 (permalink)  
Old 04-23-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,092

Code:
sed -n '/pattern/ {
s/^.*pattern\(.\{7\}\).*$/\1/
p
}' a.txt

  #4 (permalink)  
Old 04-23-2009
anushree.a anushree.a is offline
Registered User
  
 

Join Date: May 2008
Posts: 87
Thank you guys... It worked fine.. extracted exactly what i wanted... Thank you very much

Anushree.a
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 12:06 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