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!

change tab by &

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
ES
Hi,
I've a large file as:
1 2 3 44 8
8 2 6 55 9
2 3 6 85 6
...

I want to change it by:
1&2&3&44&8
8&2&6&55&9
2&3&6&85&6

How can I do it?
Thanks.
 
Hi

Code:
tr '\t' '&' < /input/file

[gray]# or[/gray]

sed 's/\t/\&/g' /input/file

[gray]# or[/gray]

awk '{gsub(/\t/,"\\&")}1' /input/file

[gray]# or[/gray]

perl -pe 's/\t/\&/g' /input/file

[gray]# or[/gray]

ruby -pe 'gsub /\t/,"&"' /input/file

[gray]# or[/gray]

while read l; do echo "${l//$'\t'/&}"; done < /input/file
Tested with GNU [tt]sed, [tt]gawk[/tt], [tt]mawk[/tt] and [tt]bash[/tt].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top