find replace in file

Vlearns
Vlearns used Ask the Experts™
on
sample.txt

PERM = 444
OWNER = root
GROUP = wheel

f - - - share/htdocs/include/ar/mail/taglines/taglines.xml ar/taglines.xml
f - - - share/htdocs/include/au/mail/taglines/taglines.xml au/taglines.xml
f - - - share/htdocs/include/b5/mail/taglines/taglines.xml b5/taglines.xml
f - - - share/htdocs/include/br/mail/taglines/taglines.xml br/taglines.xml
f - - - share/htdocs/include/ca/mail/taglines/taglines.xml ca/taglines.xml
f - - - share/htdocs/include/cf/mail/taglines/taglines.xml cf/taglines.xml
f - - - share/htdocs/include/cn/mail/taglines/taglines.xml cn/taglines.xml
f - - - share/htdocs/include/de/mail/taglines/taglines.xml de/taglines.xml


result.txt

PERM = 444
OWNER = root
GROUP = wheel

f - - - share/htdocs/include/ar/mail/taglines/taglines.xml ../trunk/aa/mail/taglines/taglines.xml
f - - - share/htdocs/include/au/mail/taglines/taglines.xml ../trunk/au/mail/taglines/taglines.xml


replace each line in  the last (6th column) such that:


basically convert

aa/taglines.xml

to
../trunk/aa/mail/taglines/taglines.xml

basically

INTL/tagines.xml

to

../trunk/INTL/mail/taglines/taglines.xml

in the last column....

can i do it using command line perl/awk?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sure.  This should do it...

perl -pe 's{\s+(\w)/taglines.xml\s*$}{ ../trunk/$1/mail/taglines/taglines.xml}' sample.txt > results.txt
Slight typo...

perl -pe 's{\s+(\w+)/taglines.xml\s*$}{ ../trunk/$1/mail/taglines/taglines.xml}' sample.txt > results.txt

Author

Commented:
added a newline

 perl -pe 's{\s+(\w+)/taglines.xml\s*$}{ ../trunk/$1/mail/taglines/taglines.xml\n}'  sample.txt  >  results.txt

can you drop a line on how this regex works to help me understand :)


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial