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
Extract string between <> rakeshou Shell Programming and Scripting 14 11-21-2007 10:10 AM
How to Extract string? namrata5 High Level Programming 2 10-24-2007 12:17 AM
Extract digits at end of string offirc Shell Programming and Scripting 6 11-20-2006 08:57 AM
Extract String sehgalniraj UNIX for Dummies Questions & Answers 1 09-25-2006 09:35 AM
How to extract a portion of a string from the whole string ds_sastry UNIX for Dummies Questions & Answers 2 09-29-2001 07:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-14-2005
Registered User
 

Join Date: Jul 2005
Posts: 18
Extract String

Hello. I would like to extract the word "PATTERN" from a file that occurs on mulitple lines:
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN40130656410423N}

Thank you.
Reply With Quote
Forum Sponsor
  #2  
Old 11-14-2005
Registered User
 

Join Date: Nov 2005
Location: cyberjaya
Posts: 85
$ cat aa
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN40130656410423N}
$ cat aa|sed -e "s/PATTERN//g"
{1:5TIROEKUDRSH0027000755}{2:O435142305111440130656410423N}
Reply With Quote
  #3  
Old 11-14-2005
Registered User
 

Join Date: Jul 2005
Posts: 18
Thank you. Let me provide more detail. I would like to get the word "Pattern" plus the next 5 characters following:

In:
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN40130656410423N}
Out:
PATTERN40130

Thanks.
Reply With Quote
  #4  
Old 11-14-2005
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,644
Quote:
Originally Posted by ashterix
$ cat aa
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN40130656410423N}
$ cat aa|sed -e "s/PATTERN//g"
{1:5TIROEKUDRSH0027000755}{2:O435142305111440130656410423N}
Now there is a UUOC.

In resonse to the second question:
Code:
sed -n 's/.*\(PATTERN.....\).*/\1/' file
Reply With Quote
  #5  
Old 11-14-2005
Registered User
 

Join Date: Nov 2005
Location: cyberjaya
Posts: 85
the best i can do so far....

$ cat aa
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN40130656410423N}
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN50130656410423N}
{1:5TIROEKUDRSH0027000755}{2:O4351423051114PATTERN60130656410423N}
$ while read all
> do
> expr substr "$all" 44 12
> done < aa
PATTERN40130
PATTERN50130
PATTERN60130
Reply With Quote
  #6  
Old 11-14-2005
Registered User
 

Join Date: Jul 2005
Posts: 18
Thank you.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




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