COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### awk question 209170

• Email
• Follow

I am in the process of writing a script that would read input from a
file containing 2 columns and would screen out and list only the
columns that contain "0".  e.g,.

col 1    col 2
3333      542
4321       0
5541       0
5555       432

so I would want

col 1     col 2
4321       0
5541       0

I am new to programing and would very much like input to get the
results:  The script looke like
awk /^[0]$/ '{ print$1, $2 }' file > file1 2>&1 obviously the above is not working Thanks   0 Reply jawadhus 5/20/2004 5:15:57 PM See related articles to this posting In article <54078e50.0405200915.21fa7a4e@posting.google.com>, Jawad H <jawadhus@lycos.com> wrote: >I am in the process of writing a script that would read input from a >file containing 2 columns and would screen out and list only the >columns that contain "0". e.g,. > >col 1 col 2 >3333 542 >4321 0 >5541 0 >5555 432 > >so I would want > >col 1 col 2 >4321 0 >5541 0 > >I am new to programing and would very much like input to get the >results: The script looke like >awk /^[0]$/ '{ print $1,$2 }' file > file1 2>&1
>
>obviously the above is not working
>Thanks

awk '$1==0 ||$2==0' infile > outfile

Chuck Demas

--
Eat Healthy        |   _ _   | Nothing would be done at all,
Stay Fit           |   @ @   | If a man waited to do it so well,
Die Anyway         |    v    | That no one could find fault with it.
demas@theworld.com |  \___/  | http://world.std.com/~cpd

 0


> I am in the process of writing a script that would read input from a
> file containing 2 columns and would screen out and list only the
> columns that contain "0".  e.g,.

Yes, I know. You posted this question and got an answer 3 hours ago on
comp.unix.shell.

Ed.


 0

Jawad H <jawadhus@lycos.com> wrote:
>I am in the process of writing a script that would read input from a
>file containing 2 columns and would screen out and list only the
>columns that contain "0".  e.g,.
>
>col 1    col 2
>3333      542
>4321       0
>5541       0
>5555       432

awk '! $1*$2'

Martin Neitzel

 0

3 Replies
120 Views

Similar Articles

12/19/2013 6:23:28 PM
page loaded in 61480 ms. (0)

Similar Artilces:

Basic AWK question: set shell vars from inside awk.
Hi all I am new to awk. Trying to parse "test" from the following input from inside a shell script. a=test.val.something echo $a | awk '{ print substr($1,1,4) }' The above works fine, but I would like the output (or return value from awk) in another shell variable. I tried doing the following. Trial 1 (did not work): ================ a=test.val.something b=var echo $a | awk '{$'$b' = substr($1,1,4) }' echo $var,$b Trial 2 (did not work): ================ a=test.val.someth...

More awk questions
Hi again, I have a file with a bunch of usernames in a single line per group (/var/etc/group) - I want to extract each group to another file in columnar format. This is what I got so far: cat group | grep group1 > group1.file awk '{FS=","};{print $1}' group1.file Awk gives me the first username but not the subsequent ones...I think I need a variable defined, but I don't know how to pass it to awk. Any sugesstions? TIA, Ben p.s. group1.file is comma delimited Ben wrote: > Hi again, > > I have a file with a bunch of usernames in a single line per group... question on awk Hi All, I want to be able to read the contents of a file as below:- ================================== There are 4 occurrences These occurrences are listed below: machine1---RUNNING machine2---STOPPED machine3---WORKING machine4---RUNNING ================================== I want the script to pick all the machines in RUNNING state i.e. machines1 and 4 and assign their names to a variable for further manipulation. Do I use awk? Please help TIA On Fri, 04 Jan 2008 08:39:15 -0800, Zinger wrote: > Hi All, > > I want to be able to read the contents of a file as below:- > &g... awk script question I am have very little experiece in awk scripting but I have been asked to debug a problem. I have narrowed the problem to this part of the code. Could someone please tell me what the following part of an .awk script does? {if (substr($0,43,14) ~ /^Sales Order :$/) { print "FLID0300~" substr($0,62,8); sub (substr($0,43,25)," "); print "\\left 0.0"; print "\\space lines 19"; print "\\font courier, 9.75"; print$0; next; } Thanks in advance, Rob Blind Squirrel wrote: > I am have very little experiece in...

AWK question #2
Hi All, I have a question, I have a data coming through like this; Problem='A' , 'B' , 'C' , 'D' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' When I use awk like this; echo $Problem |awk -F, '{print$1}' I see only 'A' on the command line. I am trying to put the variable Problem in a loop so that I can print one by one like this ; 'A', 'B', 'C', 'D', .... 'L' Can anyone please give me suggestion. Thanks "pawan_test" <sridhara007@gma...

awk pipes question...
I am not sure if should use awk pipes in this manner, but here I go anyway command | awk '/expression/ {print $1}' gives me a list like this: object1 object2 object3 I would like to do command2 object1 command2 object2 command2 object3 Any advice? TIA On 11 Apr 2007 08:29:53 -0700, "Mag Gam" <magawake@gmail.com> wrote: > I am not sure if should use awk pipes in this manner, but here I go > anyway > command | awk '/expression/ {print$1}' gives me a list like this: > object1 object2 object3 > I would like to do command2 object1 command2 ...

AWK/SED Question
I have a text file like: P12345a P123456gs AA1234a AA1234567g p123456A The first or first two characters can be letters (upper and/or lower case) followed by a variable length of numbers. I want to truncate the letters on the end of the string. End result should read: P12345 P123456 AA1234 AA1234567 p123456 2007-01-10, 11:14(-08), JD: > I have a text file like: > P12345a > P123456gs > AA1234a > AA1234567g > p123456A > > The first or first two characters can be letters (upper and/or lower > case) followed by a variable length of numbers. I want to truncate the &...

awk question 500023
Hi, Forgive the silly question, but could someone tell me why, if this works.. awk -F: '{ print $1; print$2; print $3 }' /etc/passwd .... this doesn't .. find /etc -name "passwd" -exec awk -F: '{ print$1; print $2; print$3 }' {} \; ...? Thanks. -- unix@zeouane.org unixSPAM@zeouane.org wrote: > Hi, > Forgive the silly question, but could someone tell me why, if this > works.. > > awk -F: '{ print $1; print$2; print $3 }' /etc/passwd > > ... this doesn't .. > > find /etc -name "passwd" -... awk question 497889 I am new to programming and I am trying to put up a script that would read 2 columns of line inputs and produce the result of only those values that matches "0" as the the ID. e.g, column1 column2 61433 342 66666 0 123567 43 42221 0 Hence I would only like to see: column1 column2 66666 0 42221 0 I am doing something like awk /^[0]$/ '{ print $1,$2 }' file > file1 2>&1. Obviously, its not working. I would appreciate any help!! Thanks Jawad H wrote: > I am new to programming and I am trying to put up a script that woul...