Print ALL lines except if field is 999


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print ALL lines except if field is 999
# 1  
Old 11-05-2014
Print ALL lines except if field is 999

Hi All!!! :-)

I need a command that will print each line of a text file UNLESS the 3rd field of that line is equal to the number 999. (space seperated fields)

Solaris10/BASH SHELL:

INPUT.TXT
Code:
aaa bbb 111 222
ccc ddd 333 444
eee fff 999 555
ggg hhh 666 777
aaa bbb 999 222
ccc ddd 333 444

OUTPUT.TXT
Code:
aaa bbb 111 222
ccc ddd 333 444
ggg hhh 666 777
ccc ddd 333 444

The INPUT.TXT file might have 5 or 10 fields, but it is field 3=999 that I dont want. I'm hoping there is a bash shell command (awk?) that could do this.

Thank you so very much!
Take cares!
-aj

Last edited by Scrutinizer; 11-06-2014 at 03:16 PM.. Reason: Added code tags
# 2  
Old 11-05-2014
Please use code tags as required by forum rules!

Any attempts from your side?
# 3  
Old 11-05-2014
Code:
awk '{if $3=999 print $0}' INPUT.TXT > OUTPUT.TXT

I know that probably wont work...but it helps get the idea out there of what we need (hope)
# 4  
Old 11-05-2014
Code:
awk '$3 !~ "999"' input.file > output.file

Fixing yours:

Code:
awk '{if ($3 != "999") print $0}' INPUT.TXT > OUTPUT.TXT


Last edited by Aia; 11-05-2014 at 03:37 PM..
This User Gave Thanks to Aia For This Post:
# 5  
Old 11-05-2014
That has many an syntax error plus a logical one. Correcting the syntaxes awk '{if ($3==999) print $0}' fileyieldseee fff 999 555
aaa bbb 999 222
and shows the logical one. Try
Code:
 awk '$3!=999' file
aaa bbb 111 222
ccc ddd 333 444
ggg hhh 666 777
ccc ddd 333 444

This User Gave Thanks to RudiC For This Post:
# 6  
Old 11-05-2014
NICE!! thanks so much!
# 7  
Old 11-05-2014
@Aia: That would suppress lines with 1999 or 99921234 as well... well, the first, unedited version ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk - If field value of consecutive records are the identical print portion of lines

I have some data that looks like this: PXD= ZW< 1,6 QR> QRJ== 1,2(5) QR> QRJ== 4,1(2) QR> QRJ== 4,2 QRB= QRB 4,2 QWM QWM 6,2 R<C ZW< 11,2 R<H= R<J= 6,1 R>H XZJ= 1,2(2) R>H XZJ= 2,6(2) R>H XZJ= 4,1(2) R>H XZJ= 6,2 RDP RDP 1,2 What I would like to do is if fields $1 and $2 are... (5 Replies)
Discussion started by: jvoot
5 Replies

2. UNIX for Beginners Questions & Answers

Print lines based upon unique values in Nth field

For some reason I am having difficulty performing what should be a fairly easy task. I would like to print lines of a file that have a unique value in the first field. For example, I have a large data-set with the following excerpt: PS003,001 MZMWR/ L-DWD// * PS003,001... (4 Replies)
Discussion started by: jvoot
4 Replies

3. Shell Programming and Scripting

awk to print lines based on text in field and value in two additional fields

In the awk below I am trying to print the entire line, along with the header row, if $2 is SNV or MNV or INDEL. If that condition is met or is true, and $3 is less than or equal to 0.05, then in $7 the sub pattern :GMAF= is found and the value after the = sign is checked. If that value is less than... (0 Replies)
Discussion started by: cmccabe
0 Replies

4. Shell Programming and Scripting

Print field after pattern in all lines

data: hello--hello1--hello2--#growncars#vello--hello3--hello4--jello#growncars#dello--gello--gelloA--gelloB#growncars# I want to be able to print all the values that are found between the patterns "#growncars#" and the next "#growncars#" on the same line. so the output should be: ... (8 Replies)
Discussion started by: SkySmart
8 Replies

5. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

6. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

7. Shell Programming and Scripting

Using awk, print all the lines where field 8 is equal to x

Using awk, print all the lines where field 8 is equal to x I really did try, but this awk thing is really hard to figure out. file1.txt"Georgia","Atlanta","2011-11-02","x","","","","" "California","Los Angeles","2011-11-03","x","","","",""... (2 Replies)
Discussion started by: charles33
2 Replies

8. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

9. Shell Programming and Scripting

print running field average for a set of lines

Hi everyone, I have a program that generates logs that contains sections like this: IMAGE INPUT 81 0 0.995 2449470 0 1726 368 1 0.0635 0.3291 82 0 1.001 2448013 0 1666 365 1 0.0649 0.3235 83 0 1.009 2444822 0 1697 371 1 ... (3 Replies)
Discussion started by: euval
3 Replies

10. Shell Programming and Scripting

Print lines where there's no indent on the first field

Hi All, I need a code to print those lines where there's NO indents on the 1st field Example shown below. I tried to use the below codes but i am not able to see the expected result. Can any expert give any advise ? My Code cat filename| awk '$1 ~ /^+$/ {print $0}' Input 1199 ... (7 Replies)
Discussion started by: Raynon
7 Replies
Login or Register to Ask a Question