Adding ";" (semi-colon) in each space between hour and filename

Got here a list, as follows:

07:41 0840228.32P379995.de472.netzwerk.com.br,S=307582,W=311813:2,
04:11 1574312.116821186.der472.netzwerk.com.br,S=301166,W=307582:2,
06:22 1540376.98P379995.der472.netzwerk.com.br,S=311813,W=312391:2,
03:39 8712441.254782468.de472.netzwerk.com.br,S=307387,W=311615:2,
07:35 9841630.971395138.de472.netzwerk.com.br,S=303039,W=303039:2,
01:16 2369857.123688174.de472.netzwerk.com.br,S=298927,W=311615:2,
01:08 1845871.564387663.de472.netzwerk.com.br,S=304067,W=305586:2,
08:07 1236913.325890982.de472.netzwerk.com.br,S=299941,W=304067:2,
05:70 1086215.397447162.de472.netzwerk.com.br,S=306747,W=309789:2,
06:41 9513575.225890982.de472.netzwerk.com.br,S=305586,W=306747:2,
01:70 1965849.125749892.de472.netzwerk.com.br,S=313423,W=309171:2,
09:12 9564136.687415393.de472.netzwerk.com.br,S=309171,W=313423:2,

Anyway could be added a “;” (semi-colon) in each space between hour and file name, so that would result as follows?

07:41;0840228.32P379995.de472.netzwerk.com.br,S=307582,W=311813:2,
04:11;1574312.116821186.der472.netzwerk.com.br,S=301166,W=307582:2,
06:22;1540376.98P379995.der472.netzwerk.com.br,S=311813,W=312391:2,
03:39;8712441.254782468.de472.netzwerk.com.br,S=307387,W=311615:2,
07:35;9841630.971395138.de472.netzwerk.com.br,S=303039,W=303039:2,
01:16;2369857.123688174.de472.netzwerk.com.br,S=298927,W=311615:2,
01:08;1845871.564387663.de472.netzwerk.com.br,S=304067,W=305586:2,
08:07;1236913.325890982.de472.netzwerk.com.br,S=299941,W=304067:2,
05:70;1086215.397447162.de472.netzwerk.com.br,S=306747,W=309789:2,
06:41;9513575.225890982.de472.netzwerk.com.br,S=305586,W=306747:2,
01:70;1965849.125749892.de472.netzwerk.com.br,S=313423,W=309171:2,
09:12;9564136.687415393.de472.netzwerk.com.br,S=309171,W=313423:2,
Asked By: Rubem74

||

Since there are no other space characters in your list, you can use sed to replace the first space character in each line with a semicolon:

sed 's/ /;/' file
Answered By: Freddy

This can be done with awk or sed:

awk '{print $1";"$2}' file

awk -F ' ' '{print $1,$2}' OFS=";" file

sed 's| |;|' file

The first awk command prints a ; between the first and second column and the second converts the space delimiter to a ;. The sed command simply replaces the space with a ;. To edit the file in place with sed:

sed -i 's| |;|' file

With awk, assuming that the version is 4.1.0 or later:

awk -i inplace '{print $1";"$2}' file

awk -i inplace -F ' ' '{print $1,$2}' OFS=";" filename
Answered By: Nasir Riley

Had similar problem at an email server, just put this list in a file01.txt text file, then apply following command:

cat file01.txt | sed 's/[ t]/;/g' > file02.txt

Answered By: Waldemar22
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.