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
Extract string between <> rakeshou Shell Programming and Scripting 14 11-21-2007 01:10 PM
How to Extract string? namrata5 High Level Programming 2 10-24-2007 03:17 AM
Extract digits at end of string offirc Shell Programming and Scripting 6 11-20-2006 11:57 AM
Extract String sehgalniraj UNIX for Dummies Questions & Answers 1 09-25-2006 12:35 PM
How to extract a portion of a string from the whole string ds_sastry UNIX for Dummies Questions & Answers 2 09-29-2001 10:40 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 11-14-2005
bestbuyernc bestbuyernc is offline
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.
  #2 (permalink)  
Old 11-14-2005
ashterix ashterix is offline
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}
  #3 (permalink)  
Old 11-14-2005
bestbuyernc bestbuyernc is offline
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.
  #4 (permalink)  
Old 11-14-2005
ashterix ashterix is offline
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
  #5 (permalink)  
Old 11-14-2005
bestbuyernc bestbuyernc is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 18
Thank you.
  #6 (permalink)  
Old 11-14-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,211
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
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 02:29 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