Reputation: 826
I have the following file:
aaaa
bbbb
aaaabbbb
and I wish to have the following ouput:
|aaaa|
|bbbb|
|aaaabbbb|
I tried using:
for i in aaaa bbbb aaaabbbb
do
awk '{ sub ("${i}", "|"${i}"|", $1 }1' input
done
But I do not get the desired output. Any help is appreciated, Thanks.
Upvotes: 0
Views: 55
Reputation: 5298
With sed:
sed 's/.*/|&|/g' File
.*
will match the entire line. &
=> the pattern that was matched which will be .* (entire line)
. Add |
around the matched pattern.
For inplace substitution: sed -i 's/.*/|&|/g' File
Upvotes: 1
Reputation: 41460
You can do
awk '{print "|"$0"|"}' file
or
awk '{$0="|"$0"|"}1' file
or as twalberg points out, you can use sed
sed 's/^\|$/|/g' file
This replace start anchor ^
or end anchor $
with |
Upvotes: 2