If the value > 100 delete the line with awk or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If the value > 100 delete the line with awk or sed
# 1  
Old 05-29-2014
If the value > 100 delete the line with awk or sed

if the value > 100 delete the line

Code:

delay time:  42.978 ms
delay time:  43.684 ms
delay time:  41.082 ms
delay time:  44.845 ms
delay time:  40000.057 ms
delay time:  41.158 ms
delay time:  42.239 ms
delay time:  50.579 ms
delay time:  46.334 ms

to

Code:
delay time:  42.978 ms
delay time:  43.684 ms
delay time:  41.082 ms
delay time:  44.845 ms
delay time:  41.158 ms
delay time:  42.239 ms
delay time:  50.579 ms
delay time:  46.334 ms

# 2  
Old 05-29-2014
Code:
awk '$3>100{next}1' file

Code:
awk '$3<100' file

Code:
awk '!($3>100)' file

# 3  
Old 05-29-2014
Thanks ,I want to directly change the file
# 4  
Old 05-29-2014
Try like this

Code:
$ awk '!($3>100)' file > /tmp/tmp.file && mv /tmp/tmp.file file

OR

Code:
$ awk '!($3>100)' file > my_tmp && cat my_tmp >file && rm  my_tmp

# 5  
Old 05-29-2014
I usually do the backup first
Code:
cp -p file file.old && awk '$3<=100' file.old > file && rm file.old

If I want to keep the backup I simply omit (or hash-out) the rm part.
# 6  
Old 05-29-2014
on my mac, i add the int math:

Code:
awk 'int($3)<100' file

# 7  
Old 06-01-2014
Quote:
Originally Posted by protocomm
on my mac, i add the int math:

Code:
awk 'int($3)<100' file

The request was to delete lines where $3 > 100. The code above will also delete lines where $3 == 100. And, by adding the int($3) instead of just $3, if you correct your code to use <= instead of < (as shown in other suggestions in this thread that would work correctly), your code would keep values less than 101 (such as 100.999 ms) instead of just keeping values less than or equal to 100.000.

Last edited by Don Cragun; 06-01-2014 at 02:15 AM.. Reason: Fix typo.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

2. Shell Programming and Scripting

sed or awk delete character in the lines before and after the matching line

Sample file: This is line one, this is another line, this is the PRIMARY INDEX line l ; This is another line The command should find the line with “PRIMARY INDEX” and remove the last character from the line preceding it (in this case , comma) and remove the first character from the line... (5 Replies)
Discussion started by: KC_Rules
5 Replies

3. Shell Programming and Scripting

sed command to delete line

HI, Im using the below commmand to delete lines having "(" at the start of a line. sed -e '/^(/d' But i need a command to delete lines that has only "(" in it and no other strings. infile - asdf asdf ( asdf ( asd outfile (1 Reply)
Discussion started by: dvah
1 Replies

4. Shell Programming and Scripting

Delete line with sed or awk (with specified condition)

Hello. I'm trying to delete the lines of a file does not contain the letter "T " (for example) at position 26. So far, I could only print the result: awk '{if (substr ($ 1,1,26)! ~ / T /) print}' file.txt How I can do to eliminate the lines that meet this condition? Help please. ... (4 Replies)
Discussion started by: </kida>
4 Replies

5. Shell Programming and Scripting

Sed or Grep to delete line containing patter plus extra line

I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out: Delete every line containing the word CEN and the next line as well. ie. test.txt blue 324 CEN green red blue 324 CEN green red blue to produce:... (2 Replies)
Discussion started by: rocketman88
2 Replies

6. Shell Programming and Scripting

USING sed to delete a line

Please let me know wat would be sed command to delete any partcular line from a file and also moving lines below it to up. ie wen line #9 is deleted data in line #10 should move to #9 and so on. (2 Replies)
Discussion started by: fidelis
2 Replies

7. UNIX for Dummies Questions & Answers

Using awk to get a line number to delete, piping through sed

Alright, I'm sure there's a more efficient way to do this... I'm not an expert by any means. What I'm trying to do is search a file for lines that match the two input words (first name, last name) in order to remove that line. The removal part is what I'm struggling with. Here is my code: echo... (4 Replies)
Discussion started by: lazypeterson
4 Replies

8. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies

9. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

10. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies
Login or Register to Ask a Question