Reputation: 241
I have a line of plain text that i need to wrap in a '<' and '/>'.
So I can do this perl -pe 's/^/</' myfile
and then do it again substituting the ^
with a $
Is there anyway to do this with one line of code instead of iterating twice over the file ?
Could it be done better in sed or awk ? How ?
Upvotes: 1
Views: 1074
Reputation: 1482
yet another way ( but faster :-) )
perl -i -ne 'chomp;print "<$_>\n"' myfile
Upvotes: 2
Reputation: 30273
perl -pe 's/^.*$/<$0\/>/mg' myfile
EDIT: The above found incorrect—see comments by @cjm, below.
Upvotes: 0
Reputation: 62109
perl -pe 's/^/</; s!$!/>!' myfile
You can use any number of statements; just separate them with a semicolon. And use alternate delimiters when your regex includes a /
for clarity.
Upvotes: 3