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
SED Search Pattern and Replace with the Pattern racbern Shell Programming and Scripting 4 03-15-2008 05:59 AM
find pattern and replace another field sergiioo Shell Programming and Scripting 3 04-11-2007 01:19 AM
Search for a Pattern and Replace sbasetty Shell Programming and Scripting 6 10-19-2006 01:35 PM
find and replace a pattern in a file krishnamaraju Shell Programming and Scripting 1 08-29-2006 11:02 AM
find pattern in FILES and replace it ?? tamer UNIX for Dummies Questions & Answers 4 03-03-2001 10:30 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 09-15-2007
maridhasan maridhasan is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 2
Find a pattern and replace using sed.

Hi I need to help on finding the below pattern using sed
<b><a href="/home/document.do?assetkey=x-y-abcde-1&searchclause=photo">

and replace as below in the same line on the index file.
<b><a href="/abcde.html">

thx in advance.
Mari
  #2 (permalink)  
Old 09-15-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
sed 's!<b><a href="/home/document.do?assetkey=x-y-abcde-1&searchclause=photo">!<b><a href="/abcde.html">!' input_file.txt
  #3 (permalink)  
Old 09-15-2007
maridhasan maridhasan is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 2
Find a pattern and replace using sed.

Thanks for the reply,

But, my input_file.txt will have multiple lines like

<b><a href="/home/document.do?assetkey=x-y-abcde-1&searchclause=photo">
<b><a href="/home/document.do?assetkey=x-y-12345-1&searchclause=photo">
<b><a href="/home/document.do?assetkey=x-y-xvyab-1&searchclause=photo">

<b><a href="/home/document.do?assetkey=x-y-56789-1&searchclause=river">
<b><a href="/home/document.do?assetkey=x-y-12345-1&searchclause=river">


after processing the each line from the input_file.txt, I need the ouput files like

abcde.html
12345.html
xvyab.html
56789.html
12345.html

Need furtehr help on this.

thx & rds,
Mari

Last edited by maridhasan; 09-15-2007 at 11:23 AM..
  #4 (permalink)  
Old 09-15-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Code:
cut -d "=" -f3 input_file.txt |cut -d "-" -f3|sed '/^$/d'|sed -e 's/$/\.html/'
  #5 (permalink)  
Old 09-15-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,537
Code:
awk '/assetkey=x-y/ { 	gsub(/.*assetkey=x-y-/,"")
	gsub(/-1&searchclause.*/,"")
	print $0".html"
     } ' "file"
or
Code:
awk 'BEGIN{FS="-"}
/assetkey=x-y/{
   print $3".html"
}' "file"

Last edited by ghostdog74; 09-15-2007 at 12:38 PM..
  #6 (permalink)  
Old 09-18-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
try this one

input:
Code:
<b><a href="/home/document.do?assetkey=x-y-abcde-1&searchclause=photo">
<b><a href="/home/document.do?assetkey=x-y-12345-1&searchclause=photo">
<b><a href="/home/document.do?assetkey=x-y-xvyab-1&searchclause=photo">

<b><a href="/home/document.do?assetkey=x-y-56789-1&searchclause=river">
<b><a href="/home/document.do?assetkey=x-y-12345-1&searchclause=river">
output:

Code:
<b><a href="/abcde.html">
<b><a href="/12345.html">
<b><a href="/xvyab.html">
<b><a href="/56789.html">
<b><a href="/12345.html">
code:
Code:
cat a | sed '/^$/d' > c
cat c | awk 'BEGIN{FS="-"}
{
printf("%s%s%s\n","<b><a href=\"/",$3,".html\">")
}'
rm c
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 11:12 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