Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Removing delimiter

by brkstr (Novice)
on Oct 02, 2003 at 15:48 UTC ( [id://295956]=perlquestion: print w/replies, xml ) Need Help??

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

Hello all
I am having trouble trying to remove a "," delimiter from a .txt file. testdata.txt has data that is delimited (",") and I want to remove the delimiter.
Awhile ago you all helped me with code examples. i.e.
perl -pi.bak 's/,//' file.out and $line =~ tr/,//d;

My script looks like
#!c:perl\bin\perl.exe perl -pi.bak 's/,//' testdata.txt #$line =~ tr/,//d;

I have been playing with variations of the code. But me being new to this I know I am missing something. A push in the right direction would be greatly appreciated.

Thanks
Scott

Replies are listed 'Best First'.
Re: Removing delimiter
by helgi (Hermit) on Oct 02, 2003 at 16:07 UTC
    You're getting two things mixed up. The code you were using is meant to be run from the command line, not inside a script. Your script should look something like:

    #!C:/Perl/bin/perl.exe -pi.bak tr/,//d;

    And run it like so:

    C:\>script.pl testdata.txt
    I hope this helps. This of course assumes that you just want to remove the commas and not replace them with anything else.


    --
    Regards,
    Helgi Briem
    hbriem AT simnet DOT is
Re: Removing delimiter
by thinker (Parson) on Oct 02, 2003 at 15:58 UTC

    Hi brkstr,

    The following should do what you ask, leaving the original file in FILENAME.bak

    perl -pi.bak -e 's/,//g' FILENAME

    Hope this helps

    thinker

Re: Removing delimiter
by brkstr (Novice) on Oct 02, 2003 at 17:57 UTC
    thinker & Helgi,

    Thanks your suggestions helped. Also helgi, your clarification about how it was ran cleared a lot of confusion.

    Thanks again
    Scott
Re: Removing delimiter
by inman (Curate) on Oct 03, 2003 at 13:15 UTC
    You might want to look at the module Text::CSV. It should help you process comma delimited data that contains escaped commas as part of the data value.

    ... but if your data is simple then stick with the substitution mentioned earlier.

    Inman

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://295956]
Approved by HyperZonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found