sed magic!

Hi,

I have this line in my script, and works perfect!
tran= "$(sed = "$fname" | sed "/./N; s/\n/: /" | sed -n "${beg},${end}p")"

$fname its a file, and gets multilines between beg and end.:
Something like this:
1: line a
2: line b
3: line c

But now, I want insert in the end of each line a string, e.g. XPTO, to get a output like this:
1: line aXPTO
2: line bXPTO
3: line cXPTO

Thanks in advance

Something like this?

sed 's/.*/&XPTO/' file > newfile

Regards

Another way allways with sed :

sed 's/$/XPTO/' infile > outfile

Jean-Pierre.

No... that replace XPTO at the beginning of string

The same problem above...

At least in my console I don't get the desired result...

The two sed commands work fine for me :

> cat vibra.dat
1: line a
2: line b
3: line c
> sed 's/.*/&XPTO/' vibra.dat
1: line aXPTO
2: line bXPTO
3: line cXPTO
> sed 's/$/XPTO/' vibra.dat
1: line aXPTO
2: line bXPTO
3: line cXPTO
~/Unix>

Jean-Pierre.

Also for me... I'm using a file to big, and the lines... errr :o

anyway. thank you very much. problem solved :b:

All the work can be do with a single awk command :

> cat vibra0.sh
beg=2
end=4
tran="$(awk 'NR==b,NR==e { print NR, $0 "XPTO" }' b=${beg} e=${end} vibra0.dat)"
echo "${tran}"
> cat vibra0.dat
line a
line b
line c
line d
line e
line f
> vibra0.sh
2 line bXPTO
3 line cXPTO
4 line dXPTO
>

Jean-Pierre.

each one are more fast? both are similar, right?
thanks anyway, but i wanna put two points, like:
2: line bXPTO
3: line cXPTO
4: line dXPTO

and i never find a easy way to do it with awk. and i'm also more uncomfortable with it...

Adding ':'

beg=2
end=4
tran="$(awk 'NR==b,NR==e { print NR ": " $0 "XPTO" }' b=${beg} e=${end} vibra0.dat)"
echo "${tran}"

Jean-Pierre.

thanks. i will switch for this approach... looks more light and clean :b::wink: