Link to home
Start Free TrialLog in
Avatar of Vlearns
Vlearns

asked on

find replace in file

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?

Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Sure.  This should do it...

perl -pe 's{\s+(\w)/taglines.xml\s*$}{ ../trunk/$1/mail/taglines/taglines.xml}' sample.txt > results.txt
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vlearns
Vlearns

ASKER

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 :)