Quick code question (command line)

Discussion in 'OT Technology' started by ttah, Jan 14, 2004.

  1. ttah

    ttah Guest

    I've got cygwin installed on my win2k box and am trying to use the commands like 'tr' and 'sed'. In the cygwin window I can use these to find and replace the quote character ("). But I can't get it to work in a dos window or from a batch file.

    tr -d " < blah.txt > blahout.txt
    hangs

    tr -d """ < blah.txt > blahout.txt
    hangs

    tr -d '"' < blah.txt > blahout.txt
    tr: too many arguments

    tr -d \" < blah.txt > blahout.txt
    hangs

    tr -d [="=] < blah.txt > blahout.txt
    tr: missing equivalence class character `[==]'

    tr -d [=\"=] < blah.txt > blahout.txt
    hangs

    tr -d "\" < blah.txt > blahout.txt
    removes spaces and quotes

    Any ideas? And no running stuff in a cygwin window isn't a solution.
     
  2. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,216
    Likes Received:
    521
    tr 'x' 'y' < infile > outfile

    x=character(s) to be replaced
    y=replacement character(s)

    in your case:
    tr -d '"' < blah.txt > blahout.txt

    that's a double quote inside of single quotes.
     
  3. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,216
    Likes Received:
    521
    I see you already tried that, so I don't know what's going wrong. I'll try to get a dos copy of tr and see what I can figure out.
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Have you tried using a dos variable to pass the quote?

    set quote="
    tr -d %quote% < blah.txt > blahout.txt

    I mean the problem is that Win2K uses the quote to group arguments together (ie eliminating the space). Not sure if the above would work but give it a shot
     
  5. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,216
    Likes Received:
    521
    Looks like a bug in the dos version of tr. It's taking your redirection operators as part of the argument.

    And it's not hanging - it's waiting for standard input, i.e. your keyboard. When it looks hung, type something and press enter. It'll delete any characters from your string that appear after the -d, including spaces and punctuation - it's interpreting that as the translation set:
    It deleted all of {' .<>emopqstux} (not counting the braces).

    Edit: AHA! I found it. Do your redirection BEFORE the options:

    tr < blah.txt > blahout.txt -d \"
     
  6. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,216
    Likes Received:
    521
    Looks like the problem is only on the -d option. redirection after the arguments works fine when you're translating two sets, something like tr "def" "abc" > blah.txt
     
  7. ttah

    ttah Guest

    ahh... you guys rock!!!
     

Share This Page