Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with simple AWK command 2

Status
Not open for further replies.

longhair

MIS
Feb 7, 2001
889
US
all,

awk under dos.
attempting to write a simple awk program
i have a file with data (lista.txt) and want to put certain data from it into another file (testb.txt)
i thought the code would be:
Code:
awk {if($1!=192)} lista.txt print$1>>testb.txt
ultimately this will be placed in a .bat file. any guidance would be greatly appreciated.

regards,
longhair
 
not sure what you you're after, but I think.....

Code:
awk '$1!=192 {print $1}' lista.txt >>testb.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Something like this ?
awk "{if($1!=192) print $1}" lista.txt > testb.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
awk "$1!=192 {print $1}" lista.txt >>testb.txt

Let me know whether or not this helps.

For an introduction to Awk, see faq271-5564.

 
great minds.....

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks,

futurlet & PHV they both work. vgersh99 - yours throws a syntax error on the single quote. I knew it was something like this just couldn't quite get it. one other quick question - i thought || represented or? shouldn't
Code:
awk "{if($1!=192 || $1=ping) print $1}" lista.txt > testb.txt
print anything except 192 or ping?
thanks.
regards,
longhair
 
Here are two ways to do it:
Code:
192 != $1  &&  "ping" != $1 { print $1 }

Code:
!(192 == $1  ||  "ping" == $1 ) { print $1 }

For an introduction to Awk, see faq271-5564.
 
futurelet,

with both examples "ping" still arrives in testb.txt. thanks for the ideas. i'll continue to play around with.

regards,
longhair
 
with both examples "ping" still arrives in testb.txt.
Not when run with awk under DOS. I tested it.

Save either version in file [tt]select.awk[/tt].
Run with
[tt]awk -f select.awk infile >outfile[/tt]

If you run it with
[tt]awk -f select.awk infile [COLOR=red yellow]>>[/color]outfile[/tt]
the new output will be appended to the old contents of outfile, which may already contain "ping".
 
futurelet,

that works - another star for you.
i wasn't running it from a seperate file
i was doing it from the command line and from a .bat file with the code
Code:
awk "!(192==$1 || ping==$1) { print $1 }" lista.txt >>testb.txt
thanks for your help
regards,
longhair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top