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
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 4 03-28-2009 04:10 PM
Simple newbie grep question doubleminus UNIX for Dummies Questions & Answers 5 04-06-2008 07:05 PM
grep - searching for a specific string manthasirisha Shell Programming and Scripting 2 01-05-2006 09:24 AM
searching searching tony3101 Shell Programming and Scripting 3 06-04-2004 12:50 PM
searching for { yotoruja Shell Programming and Scripting 4 11-03-2003 10:07 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 08-26-2007
steveglevin steveglevin is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
GREP Searching for a newbie...

Hi,

I really need some help with GREP searching...

I need to find all occurances of a file reference and remove two characters from the end of the reference. For example, here are a few lines showing the text:

<image file="STRAIGHT_004CR.jpg" ALT="STRAIGHT_004CR.jpg" />
<image file="STRAIGHT_006CR.jpg" ALT="STRAIGHT_006CR.jpg" />
<image file="STRAIGHT_007CR.jpg" ALT="STRAIGHT_007CR.jpg" />

And they then need to look like:

<image file="STRAIGHT_004.jpg" ALT="STRAIGHT_004.jpg" />
<image file="STRAIGHT_006.jpg" ALT="STRAIGHT_006.jpg" />
<image file="STRAIGHT_007.jpg" ALT="STRAIGHT_007.jpg" />

I think I've written the correct search query which I think is:

_\d{3}\D\D

But I have no idea how to write the replacement string to remove the additional letters at the end of the string of 3 numbers and leave everything else in tact...

ANy help would be much appreciated...

Thanks

Steve.
  #2 (permalink)  
Old 08-26-2007
earlysame55 earlysame55 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 23
Quote:
Originally Posted by steveglevin View Post
Hi,

I really need some help with GREP searching...

I need to find all occurances of a file reference and remove two characters from the end of the reference. For example, here are a few lines showing the text:

<image file="STRAIGHT_004CR.jpg" ALT="STRAIGHT_004CR.jpg" />
<image file="STRAIGHT_006CR.jpg" ALT="STRAIGHT_006CR.jpg" />
<image file="STRAIGHT_007CR.jpg" ALT="STRAIGHT_007CR.jpg" />

And they then need to look like:

<image file="STRAIGHT_004.jpg" ALT="STRAIGHT_004.jpg" />
<image file="STRAIGHT_006.jpg" ALT="STRAIGHT_006.jpg" />
<image file="STRAIGHT_007.jpg" ALT="STRAIGHT_007.jpg" />

I think I've written the correct search query which I think is:

_\d{3}\D\D

But I have no idea how to write the replacement string to remove the additional letters at the end of the string of 3 numbers and leave everything else in tact...

ANy help would be much appreciated...

Thanks

Steve.
Hi,

try using :

sed. sed 's/CR.jpg/.jpg/g'

But make sure you have a backup of the file.
regards
  #3 (permalink)  
Old 08-26-2007
steveglevin steveglevin is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
Thanks for this...

Not sure i was very clear before, the text I need to replace has the last two letters vary so I can't specificaly request a change on a specific set of characters like 'CR'.

The text string I need to replace is made up of varying 3 digits and then 2 letters like:

000XX

But I need to remove the two letters in each instance but preserve the rest of the text around the string as in the example:

<image file="STRAIGHT_000XX.jpg" ALT="STRAIGHT_000XX.jpg" />

needs to look like:

<image file="STRAIGHT_000.jpg" ALT="STRAIGHT_000.jpg" />

I am using a text editing program to do this which supports GREP find and replace so need to know the GREP search query string which I think is _\d{3}\D\D and then the Replacement string which will remove the two letters at the end of the text which it finds...

Sorry to be a pain...

Thanks.
  #4 (permalink)  
Old 08-26-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958

Code:
sed 's/\(.*\)\(..\)\(....\)/\1\3/' filename

  #5 (permalink)  
Old 08-26-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177

Code:
sed 's/[A-Z][A-Z].jpg/.jpg/g' <file-name>

Cheers,
K
  #6 (permalink)  
Old 08-26-2007
steveglevin steveglevin is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 3
Thanks guys...!

Should work a treat...!

All the best!!
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:43 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