Avoiding "/double-quotes in the command line 
Author Message
 Avoiding "/double-quotes in the command line

I have often been plagued with problems of using a " in an awk program
invoked from the command line  - eg

      awk -F: '$2 == "B" && $8 == "Y"' filename

which under Win/Dos get well confused and effectively useless

I thought I would share a thought that came to me at 3am this
morning of how to avoid this by using the ~

i.e.
    awk -F: '$2 ~ \B\ && $8 ~ \Y\' filename

Of course this is not perfect because ~ means contains and == "..." means
equals, but for my case this was sufficient

Hope it helps others too ;-)

Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 208-455 4665, Fax (44) 208-458 9554
** See our website at http://www.*-*-*.com/ **



Sun, 24 Mar 2002 03:00:00 GMT  
 Avoiding "/double-quotes in the command line

Quote:

>I have often been plagued with problems of using a " in an awk program
>invoked from the command line  - eg

>      awk -F: '$2 == "B" && $8 == "Y"' filename

>which under Win/Dos get well confused and effectively useless

>I thought I would share a thought that came to me at 3am this
>morning of how to avoid this by using the ~

>i.e.
>    awk -F: '$2 ~ \B\ && $8 ~ \Y\' filename

>Of course this is not perfect because ~ means contains and == "..." means
>equals, but for my case this was sufficient

Don't you mean /B/ ?  (Why the backslashes?)

BTW, I note that you use T-AWK (under DOS [aka, Windows]).  As it turns out,
there are two possibles provided for you by Thompson:
        1) You could use their Toolkit shell, which behaves a lot like Unix
           csh (for better or worse...).  It does get you around most of the
           quoting problems.
        2) They also have a gadget where you can put stuff in environment
           variables and then use them on the command line.  T-AWK parses
           these like Unix environment vars - even if the shell is ordinary
           COMMAND.COM.  As a test, I just did:

           C:\tmp> set foo="bar"
           C:\tmp> awkw "BEGIN {print $foo}"
           bar
           C:\tmp>

           (in a DOS window under Win98).
           Note the use of double quotes (not single!) in the awk command
           line so that, Unix style, the env var *does* get expanded.



Sun, 24 Mar 2002 03:00:00 GMT  
 Avoiding "/double-quotes in the command line

Quote:

>I have often been plagued with problems of using a " in an awk program
>invoked from the command line  - eg

>      awk -F: '$2 == "B" && $8 == "Y"' filename

>which under Win/Dos get well confused and effectively useless

>I thought I would share a thought that came to me at 3am this
>morning of how to avoid this by using the ~

>i.e.
>    awk -F: '$2 ~ \B\ && $8 ~ \Y\' filename

>Of course this is not perfect because ~ means contains and == "..." means
>equals, but for my case this was sufficient

>Hope it helps others too ;-)

You could use anchors in your regular expression for a field:

    awk -F: '$2 ~ /^B$/ && $8 ~ /^Y$/' filename

which would be equivalent to the equals thing.

I assume you had a typo and used backslashes by accident, or is
that a DOS/Windows "feature."  :-)

Chuck Demas
Needham, Mass.
[posted and emailed]

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 24 Mar 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help with double quotes in 8.0.5 exec command under NT 4.0

2. replace single quote to double quote with an example

3. Kill Everything Before Ist Double Quote "

4. Avoiding buffer problems from command line arguments

5. Problem with "-r" command line argument

6. Dos command lines and -c "text"

7. how to split each new line into a list, considering quoted new line characters

8. How can triple quoted string avoid indentation?

9. Simple way to avoid nasty quoting?

10. How to avoid double click?

11. Avoiding double lookup procedure

12. Differences between command line and the "double-click"

 

 
Powered by phpBB® Forum Software