I just got a script who upload image file on to a web hoster; at the end I got a file with all the links (one link per line) and I would like to add [img]
at the beginning of each link and [/img]
at the end.
Asked
Active
Viewed 75 times
0

Jeff Schaller
- 67,283
- 35
- 116
- 255
2 Answers
4
If you just want to add [img]
to the start of each line in a file, and [/img]
to the end, you could do that with awk
like so:
awk '{ print "[img]" $0 "[/img]" }' infile >outfile
Or,
awk '{ printf("[img]%s[/img]\n", $0) }' infile >outfile

Kusalananda
- 333,661
3
One way, with the stream editor, sed:
sed -e 's/^/[img]/' -e 's!$![/img]!' < input > output
Here I've changed the delimiter for the second search & replacement from /
to !
so that the forward-slash in the replacement text doesn't need to be escaped. GNU sed would allow an in-place edit with the -i
option:
sed -i -e 's/^/[img]/' -e 's!$![/img]!' input
Alternatively, you could edit the file in-place with ed
:
ed -s input <<< $'1,$s/^/[img]/\n1,$s!$![/img]!\nw\nq'

Jeff Schaller
- 67,283
- 35
- 116
- 255