EX:test.txt = 1
2
3
4
5
script test.sh = sed -ne "
s/2/aaa/g
p
" test.txt >test2.txt
test2.txt = 1
aaa
3
4
When i create the file test.txt i didn't but a cariage return on the
last line.
Is there a way do to this ?
Note:I'm doing a "for file " in the script and a don't want to modify
all file with a cat of a cariage return in all file.
Thanks in advance.
Sent via Deja.com http://www.deja.com/
Before you buy.
Yep. A bug/feature(???) of many sed implementations. The
POSIX.2 answer to this plight is that sed only is designed
to work with "text files", where a text file is a file which
meets certain criteria, one of which is that every line
(including the last) is terminated by a newline character.
>Is there a way do to this ?
Three leap to mind:
* use GNU sed --- it handles this situation just fine
* use perl in a sed-like fashion:
perl -pe 's/2/aaa/g' test.txt >test2.txt
* tweak your invocation:
{ cat test.txt; echo ''; } | sed 's/2/aaa/g' >test2.txt
--Ken Pizzini