codejnki has asked for the wisdom of the Perl Monks concerning the following question:

Ok here's the deal I've got a form which outputs strings of numbers in to multiple text files. We are going to have to do number crunching on them. This is the output we get:

if you cat file1.txt you get
123
12
23

if you pull file1.txt in to vi you get
1^@2^@3
1^@2
2^@3

if i pull file1.txt in to notepad.exe you get
1 2 3
1 2
2 3

HERE'S WHAT I WANT
I would like a simple way to change this mysterious control character in to a comma so that my fil1.txt becomes
1,2,3
1,2
2,3

This is so I've got a comma delimited file (duh) and can pull it in to a spreadsheed and do all sorts of number crunching on it.

Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Search & Replace Revisited
by Kanji (Parson) on Oct 06, 2000 at 05:08 UTC
    Use s/// to replace any characters except those you want.

    perl -pi.bak -e 's#[^\d$/]#,#g' file1.txt

    Yeah, \D would have been simpler than [^\d$/], but then you'd also get the input record seperator assuming it hadn't been set to a number.

      The ^@ is a null, or \0.
      perl -pi.bak -e 's#\0#,#g' file1.txt
      --Chris

      e-mail jcwren