Delete several lines if the first line contain numbers > 200


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete several lines if the first line contain numbers > 200
# 1  
Old 10-23-2013
Delete several lines if the first line contain numbers > 200

I have a file of the following format:

Code:
$data1 size 1278
dataw
datat
datau
datai
$data2 size 456
datak
dataf
datat
datay
datal
$data3 size 154
datag
datas
datat
datar
datas
datap
$data4 size 234
datat
datat
datap
datai

so that certain line begin with $ and have the parameter "size". I want to delete the entire block of data of the lines for which "size" > 200.

In my case the output would be:

Code:
$data1 size 1278
dataw
datat
datau
datai
$data2 size 456
datak
dataf
datat
datay
datal
$data4 size 234
datat
datat
datap
datai

Any ideas? Thanks

Last edited by FelipeAd; 10-23-2013 at 08:42 AM..
# 2  
Old 10-23-2013
Assuming you want the blocks with a size > 200:
Code:
awk '/^\$/{f=$NF>200?1:0}f' file

# 3  
Old 10-23-2013
No, the size of the blocks does not match the parameter "size". What I want is to delete the block of data from one $ to the next, IF the parameter "size" is >200
# 4  
Old 10-23-2013
Quote:
Originally Posted by FelipeAd
No, the size of the blocks does not match the parameter "size". What I want is to delete the block of data from one $ to the next, IF the parameter "size" is >200
But your desired output contains only blocks of > 200:
Code:
$data1 size 1278
dataw
datat
datau
datai
$data2 size 456
datak
dataf
datat
datay
datal
$data4 size 234
datat
datat
datap
datai

# 5  
Old 10-23-2013
Sorry, misunderstanding.
I only want to keep the blocks for which the first line contain "size 'number' " where number >200.

But the number of rows for each block could also be less than 200
# 6  
Old 10-23-2013
Quote:
Originally Posted by FelipeAd
Sorry, misunderstanding.
I only want to keep the blocks for which the first line contain "size 'number' " where number >200.

But the number of rows for each block could also be less than 200
Have you tried the provided code?
Code:
awk '/^\$/{f=$NF>200?1:0}f' file

# 7  
Old 10-23-2013
Hi,
Code:
sed -e '/size \(1\{,1\}[0-9]\{,2\}\|200\)$/,/size \(20[1-9]\|2[1-9][0-9]\|[3-9][0-9][0-9]\|[1-9][0-9]\{3,\}\)/{/size \(20[1-9]\|2[1-9][0-9]\|[3-9][0-9][0-9]\|[1-9][0-9]\{3,\}\)/!d;}'  file

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

2. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

3. UNIX for Dummies Questions & Answers

Replace lines of two files by the corresponding line numbers.

I want to replace lines. The files 1 are (separated by \t) Gm01 phytozome9_0 three_prime_UTR 70641 70759 . - . ID=PAC:26323927.three_prime_UTR.1;Parent=PAC:26323927;pacid=26323927 Gm01 phytozome9_0 three_prime_UTR 90230 90692 . - . ... (1 Reply)
Discussion started by: grace_shen
1 Replies

4. Shell Programming and Scripting

sed pattern fails to delete line of numbers

We are using Red Hat Linux. I have a flat file with among other things, the following lines, which appear occasionally throughout the file: Using sed, I delete this line: L;L;L;L;R;R;R;L;R;L;R;R;R;L;L;L With: /^;;;;;*/d Works fine every time. However, I cannot delete... (6 Replies)
Discussion started by: bloomlock
6 Replies

5. Shell Programming and Scripting

Delete files having less than 200 lines

Hi All, I have some 30,000 files in one directory. The files look like this: computer networks router wire I want to remove those files which have less than 200 lines for example in the above file, the number of lines is 4. I am trying something like this: find /path/to/dir -type f... (5 Replies)
Discussion started by: shoaibjameel123
5 Replies

6. Shell Programming and Scripting

Delete lines with line numbers.

Hi, I have a file will 1000 lines.... I want to deleted some line in the file... like 800-850 lines i want to remove in that... can somebody help me..? thanks. (2 Replies)
Discussion started by: Kattoor
2 Replies

7. UNIX for Dummies Questions & Answers

Command to delete numbers at beginning of txt file line

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt awk 'NR%2==0' test1.txt >... (4 Replies)
Discussion started by: li_bi
4 Replies

8. Shell Programming and Scripting

Delete rows based on line numbers in a file

I have to find the number of rows in a file and delete those many rows in another file. For example, if I have 3 rows in a file A, i have to delete first 3 rows in anothe file B, I have the code, it works as standalone, when I merge this with m application (c with unix), it doesnt work. ... (2 Replies)
Discussion started by: Muthuraj K
2 Replies

9. Shell Programming and Scripting

how to delete records with the given line numbers

I have a file which has about 10000 records and I need to delete about 50 records from the file. I know line numbers and am using sed '134,1357,......d' filename > new file. It does not seem to be working. Please Advice (5 Replies)
Discussion started by: mad_man12
5 Replies

10. Shell Programming and Scripting

display lines b/w given line numbers

write a shell script that accepts a file name starting and ending line numbers as arguments and displays all the lines between the given line numbers:b:.help is appreciated.thank you. (3 Replies)
Discussion started by: shawz
3 Replies
Login or Register to Ask a Question