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

Hello again, sorry for a similar question, but somehow I can't make it working:

I need now to replace all instances of comma to TAB

I have tried the following:

perl -pe 's/\,/ /' input.txt > output.txt perl -pe 's/\,/\t/' input.txt > output.txt perl -pe 's/,/\t/' input.txt > output.txt

But it does not work. Could you please advise again? Thanks!

Replies are listed 'Best First'.
Re: Replace comma with tab
by choroba (Cardinal) on Apr 05, 2015 at 14:46 UTC
    Comma is not special, no need to backslash it. Did you read the whole answer? Re: Replace ".." with "," It tells you what to do to replace all the matches.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Replace comma with tab
by NetWallah (Canon) on Apr 05, 2015 at 15:08 UTC
    It works for me (with or without the "g", which replaces "globally")
    >echo this, that, and the other | perl -pe 's/,/\t/g' this that and the other
    "does not work" is not a specific enough description.

    It would help if you showed what you expect it to do, and what it actually produces for you, as well as a sample of the input data.

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

      it worked finally. After adding the "g" at the end of the command, it worked properly. I am still curious, why did it work fine without "g" for the previous task (converting ".." to ","), and did not work for converting "," to tab?
        We could probably explain if you showed us your data.

        Perhaps you had only one occurrence of double dots per line of input. Maybe something else, I can't say for sure, we need to see the data.

        Je suis Charlie.
Re: Replace comma with tab
by GrandFather (Saint) on Apr 05, 2015 at 20:50 UTC

    In every reply you say some variant of "it does not work", but not once do you tell us what the failure mode was. Did you get errors? Did it not perform the replacement you expected? Did it not replace enough times? Did it replace too many times?

    If you tell us how it failed and, in particular, show us what you got and what you expected along with the test data we have a much better chance of helping you. Take a look at I know what I mean. Why don't you? for further hints that will help you getting good answers.

    Perl is the programming world's equivalent of English