Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how insert character on file with tabs 1

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
hi,

I have several very long files of the style:
1 22 3
11 2 333
111 222 33
....

Between a column and another there is a tab. At last each row, I must put = character and between columns, I must put * character. Therefore, my output must be:

1 * 22 * 3 =
11 * 2 * 333 =
111 * 222 * 33 =
....

How can I do it?
txs
 
I'd try

Code:
sed  's/\t/ * /;s/$/ =/' </path/to/infile >/path/to/outfile

and if sed doesn't understand the \t for tab char, just hit the tab key and type the tab literally instead of the \t symbol. (Here I expanded the tab to 8 spaces):

Code:
sed  's/        / * /;s/$/ =/' </path/to/infile >/path/to/outfile


HTH,

p5wizard
 

txs, but i have a problem with tab:
i try to put \t, hit tab key and '\t', but it doesn't work for me.
 
Ok then, try awk:

awk '{
for (i=1;i<NF;i++){
printf "%s * ", $i
}
printf "%s =\n", $NF
}' /path/to/infile >/path/to/outfile


(on AIX, sed doesn't understand \t either) and in any case the sed program wasn't correct.

sed 's/[red](tab)[/red]/ * /[red]g[/red];s/$/ =/' </path/to/infile >/path/to/outfile


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top