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
nawk-how count the number of occurances of a pattern, when don't know the pattern cyber111 Shell Programming and Scripting 2 05-11-2008 03:00 AM
Find a pattern and replace using sed. maridhasan Shell Programming and Scripting 5 09-18-2007 01:43 AM
Search for a Pattern and Replace sbasetty Shell Programming and Scripting 6 10-19-2006 12:35 PM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM
how to search the pattern vasikaran UNIX for Dummies Questions & Answers 2 06-30-2005 04:34 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 03-14-2008
racbern racbern is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 26
SED Search Pattern and Replace with the Pattern

Hello All,

I have a string "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031", and I just want to extract LLSV1, but I dont get the expected result when using the sed command below.



# echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | awk '{print $4}' | sed 's/_\(LLSV[a-zA-Z0-9]\)_/\1/g'

Can you help me with the sed command how can I search a pattern and replace the whole word with the patter?

racbern
  #2 (permalink)  
Old 03-14-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,292
Assuming the pattern is preceded by "R1H_" you can try this:

Code:
echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | sed 's/.*R1H_\(.*\)_.*/\1/'
Regards
  #3 (permalink)  
Old 03-15-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
Code:
And assuming that, your interest pattern is always before the last field (_ dlimited),

$ echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | awk '{print $(NF-1)}' FS=_
LLSV1
//Jadu
  #4 (permalink)  
Old 03-15-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,502
from the sample code you provided, it seems that LLSV? is something nearly constant.
Code:
# echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" | sed 's/.*\(LLSV[a-zA-Z0-9]\).*/\1/'
LLSV1
  #5 (permalink)  
Old 03-15-2008
lijojoseph lijojoseph is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 6
If pattern is going to be the same then use this

echo "CP_STATUS OSSRC_R6_0_Shipment_R1H_CU AOM_901046 R1H_LLSV1_2008031" |cut -d ' ' -f4|cut -d _ -f2
Sponsored Links
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 09:22 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