Skip to content
Advertisement

Separate Text file to columns by ;

Please I have a text file separated by spaces. I would like to output it to columns separated by ;

example Input

31561 49215 10   1196825801480000
31561 49219 12   1196825801480000
31561 48665 14   1196825806980000

I use this code

tr " " ";" < file

My output

31561;49215;10;;;1196825801480000
31561;49219;12;;;1196825801480000
31561;48665;14;;;1196825806980000

Output desired.

31561;49215;10;1196825801480000
31561;49219;12;1196825801480000
31561;48665;14;1196825806980000

Appreciate your help.

Advertisement

Answer

awk -v OFS=';' '{$1=$1}1' file

$1=$1 is a trick to rebuild $0 with the new separator OFS=';'.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement