vibra
August 25, 2008, 10:17am
1
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
aigles
August 25, 2008, 10:33am
3
Another way allways with sed :
sed 's/$/XPTO/' infile > outfile
Jean-Pierre.
vibra
August 25, 2008, 10:39am
4
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...
aigles
August 25, 2008, 10:51am
5
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.
vibra
August 25, 2008, 11:00am
6
Also for me... I'm using a file to big, and the lines... errr :o
anyway. thank you very much. problem solved
aigles
August 25, 2008, 11:04am
7
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.
vibra
August 25, 2008, 11:09am
8
aigles:
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...
aigles
August 25, 2008, 11:17am
9
vibra:
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.
vibra
August 25, 2008, 11:37am
10
thanks. i will switch for this approach... looks more light and clean