![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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.. |
|
||||
|
Code:
awk '/assetkey=x-y/ { gsub(/.*assetkey=x-y-/,"")
gsub(/-1&searchclause.*/,"")
print $0".html"
} ' "file"
Code:
awk 'BEGIN{FS="-"}
/assetkey=x-y/{
print $3".html"
}' "file"
Last edited by ghostdog74; 09-15-2007 at 12:38 PM.. |
|
||||
|
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"> 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:
cat a | sed '/^$/d' > c
cat c | awk 'BEGIN{FS="-"}
{
printf("%s%s%s\n","<b><a href=\"/",$3,".html\">")
}'
rm c
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|