Delete lines falling in a range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete lines falling in a range
# 1  
Old 07-16-2013
Delete lines falling in a range

Hi All,

I have a file which contains lakhs of records

HTML Code:
0136812368126     03000   Statement
1237129372189     02321   JIT
0136812368126     05000   terminal
1237129372189     05001   Utilise
Is there an option to delete all lines which fall within the range 05000 to 05999?

I tried using simple grep to extract all matching lines but it's not working as expected

Code:
cat sample.txt | grep "05" > test

Please can you help?
# 2  
Old 07-16-2013
Code:
grep -v -w 05[0-9][0-9][0-9] file

# 3  
Old 07-16-2013
Are you looking to eliminate only those in secod column?
# 4  
Old 07-16-2013
Code:
awk '{if (($2>=5000)&&($2<=5900)) {next} else print }'  filename

Equivalent command
Code:
awk '($2<5000)||($2>5900)' filename


Last edited by krishmaths; 07-16-2013 at 08:13 AM.. Reason: Correction
# 5  
Old 07-16-2013
No I want the entire line which contains the pattern 05000 to be deleted or put into a separate file. Also, these lines are not continuous meaning the lines containing 05000 upto 05999 are interspersed like in the below

Code:
0136812368126     03000   Statement
1237129372189     02321   JIT
0136812368126     05000   terminal
1237129372189     02999   Utilise
0136812368126     03000   Statement
1237129372189     05001   JIT
0136812368126     04253   terminal
1237129372189     05002   Utilise

All these lines containing the pattern from 05000 to 05999 should be separated out from the file
# 6  
Old 07-16-2013
Did you try the awk solution I posted above?
# 7  
Old 07-17-2013
The first option is working! Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies

2. UNIX for Beginners Questions & Answers

How to delete row in csv file on date range?

I want to delete row in csv file , which row value from 2009-10-01 to 2011-06-03 using script.my csv row data look like: 2009-10-01 2011-03-30 2011-03-31 2011-04-01 2011-06-03 2011-06-30 2011-07-01 2011-09-28 ... (7 Replies)
Discussion started by: rakibul639
7 Replies

3. UNIX for Dummies Questions & Answers

How to display lines by range specified?

My input file is N3*123 ABC FLATS~ REF*D9*10000000001~ N3*223 ABC FLATS~ REF*D9*10000000002~ N3*323 ABC FLATS~ REF*D9*10000000003~ N3*423 ABC FLATS~ REF*D9*10000000004~ N3*523 ABC FLATS~ REF*D9*10000000005~ N3*623 ABC FLATS~ REF*D9*10000000006~ N3*723 ABC FLATS~ REF*D9*10000000007~ N3*823... (2 Replies)
Discussion started by: nsuresh316
2 Replies

4. Shell Programming and Scripting

Count occurences of a numeric string falling in a range

Dear all, I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter. INPUT: 1.dat 1.3 2.16 0.34 ...... 2.dat 1.54 0.94 3.13 ..... ... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

5. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

6. Shell Programming and Scripting

sed delete range

Hi I would like to delete ranges of text from an html file; In the sentence; aqua>Stroomprobleem in Hengelo verholpen <a href="107-01.html"><font color=yellow>107</a> With several sentences like this in that file, where the text between <a href a> varies, so it needs to be deleted in the... (2 Replies)
Discussion started by: mdop
2 Replies

7. UNIX for Dummies Questions & Answers

Date range command (and delete)

Hello. Newbie here.... I basically have a directory with tens of thousands (literally) subdirectories and need to delete those that are older than 2008 (hundreds) with all their contents. I've looked through all the RM parameters and still can't quite figure out how to specify the data range... (7 Replies)
Discussion started by: pqmomba8
7 Replies

8. Shell Programming and Scripting

Selecting a range of Lines

Hi All, Is there a way to get a range of lines from a file??? I want to search through a set of scripts and need to select the group of lines which do the FTP. Say, Line1 Line2 ftp SERVER user UNAME PASS send FILE_TO_BE_SENT close Line3 Line4 Line5 ftp SERVER1 user USER1 PASS1... (6 Replies)
Discussion started by: beinthemiddle
6 Replies

9. Shell Programming and Scripting

delete rows between closest pattern or range

Hi I am having some problom deleting the lines between two specific lines in a file. need to delete lines between two closest lines. i.e need to find the closest range or pattern in a file with repeating patterns. Sample Input: WARNING <some text in n number of lines> ERROR:2597... (10 Replies)
Discussion started by: sudheer1984
10 Replies

10. Shell Programming and Scripting

Grep a string in a range and delete the line

Hi, i need to delete a lines after searching a particular string but this searching should only happen after the 4th line.. basically imagine a file like this From: abcd.yahoo.com To: cdeb.yahoo.com Subject: hi all sdfsd sadasd asdasd dfsdf From: abcd.yahoo.com To:... (3 Replies)
Discussion started by: depakjan
3 Replies
Login or Register to Ask a Question