Using SED to delete between two blocks.....and then repeating.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using SED to delete between two blocks.....and then repeating.
# 1  
Old 09-08-2010
Using SED to delete between two blocks.....and then repeating.

Hi All

I'm still on my slow and painful self teach learning experience with SED.

My latest issue is getting my head around how best to do the following.

I have a file that's created using iwlist that I want to chop up into paragraphs then only keep the ones I see as potential threats.

I have managed to use sed to break the file up into identifiable paragraphs with a blank line as the paragraph break without too many problems, however what I want to do now is push each paragraph into an array then run various other sed scripts against each array to extract needed data.

I was trying to use something like....

Code:
echo "$IWLISTFILE" | sed -e '/StartPoint /,/\n\n/!d'

(or variations on the same) to cut everything except what's inside the StartPoint to the two newlines however it's not working as I was hoping and I can't see why. Instead it's not deleting anything or if I remove the EXCEPT in front of the delete it is deleting everything.

Could someone perhaps suggest what I'm missing/doing wrong in my understanding so that I can at least learn from the experience.

Thanks in advance.

Last edited by Scott; 09-08-2010 at 01:48 PM.. Reason: Please use code tags
# 2  
Old 09-08-2010
sed is line based so you cannot look for \n characters that way:

Try this:
Code:
sed '/StartPoint /,/^$/!d' "$IWLISTFILE"

^$ means an empty line
# 3  
Old 09-08-2010
Cripes what a tw*t I am, of course it's the obvious things you miss when you're still learning.

Thanks Scrutinizer....I'll go off and do 200 press ups now as a stupidity penance.
# 4  
Old 09-08-2010
Hi Bashingaway, I think I can safely say we are all learning here. That is what makes Unix so interesting. Have fun..

S.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete data blocks based on missing combinations

Hello masters, I am filtering data based on completeness. A (Name , Group) combination in File2 is only complete when it has data for all subgroups specified in File1. All incomplete (Name , Group) combinations do not appear in the output. So for example , Name1 Group 1 in File2 is... (6 Replies)
Discussion started by: senhia83
6 Replies

2. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

3. Shell Programming and Scripting

Sed Replace repeating pattern

Hi, I have an sqlplus output file using the character ';' as a delimiter and I would like to replace the fields without datas (i.e delimited by ';;') by ';0;' Example: my sqlplus output: 11;22;33;44;;;77;; What I would like to have: 11;22;33;44;0;0;77;0; Thanks in advance for your... (2 Replies)
Discussion started by: popesk
2 Replies

4. Shell Programming and Scripting

Problem with Sed when repeating characters

Hi all, I'm learning sed (and regular expressions) - My first little program is to replace 3 numbers in a row with 'XXX' This is what I am trying: echo '511' | sed 's/{3}/XXX/' Here is the output: defunct-macbook-pro:~ defunct$ echo '511' | sed 's/{3}/XXX/' 511For some reason, it doesnt... (2 Replies)
Discussion started by: Defunct
2 Replies

5. Shell Programming and Scripting

Sed Replace a repeating character

I have a text file and every line ends in |^ |^^ |^^^ |^^^^ I need to use sed to make all lines end it |^ regardless of the amount of carrots. The code i was using is: cat FILE | sed 's/\^\^\^/\^/g' But then they threw that curveball at me. Also is there a way to... (2 Replies)
Discussion started by: insania
2 Replies

6. Shell Programming and Scripting

Delete Blank Lines Between DHCP Host Blocks

Hi All, I have a dhcpd.conf file that gets static hosts added and removed via a shell script. After sometime, there becomes huge gaps of space ( blank lines ) between each host block. I tried a couple of sed one-liners; but, I can't seem to get the output I'm looking for. Also, I would like... (4 Replies)
Discussion started by: cstovall
4 Replies

7. UNIX for Dummies Questions & Answers

assitance with sed (repeating patterns)

hi, I need to write a command to look into a text file, find lines that contain patterns of three or more characters that repeat once, and put perenthesizes around them. so for example, the line "123test123" would be changed to "(123)test(123)" and "abcdeabcde" to "(abcde)(abcde)". any hint is... (7 Replies)
Discussion started by: metalwarrior
7 Replies

8. UNIX for Advanced & Expert Users

need assistance: sed and repeating patterns

hi, I need to write a command with sed to find all the lines in a file that contain patterns of three or more characters that repeat once and put them inside perenthezes. I cannot tell sed what pattern to look for. it should find repeated patterns automatically. example:... (1 Reply)
Discussion started by: metalwarrior
1 Replies

9. Shell Programming and Scripting

Delete blocks of lines from text file

Hello, Hello Firends, I have file like below. I want to remove selected blocks say abc,pqr,lst. how can i remove those blocks from file. zone abc { blah blah blah } zone xyz { blah blah blah } zone pqr { blah blah blah } (4 Replies)
Discussion started by: nrbhole
4 Replies

10. Shell Programming and Scripting

Delete blocks with no data..

Hi, I tried this but could not get it... here is what I need I have an xml where I get all the data in blocks but some times I get empty blocks with no data...shown below..I need to delete only those blocks with no data, I tried couple of ways but could not do it..any help is appreciated...... (1 Reply)
Discussion started by: mgirinath
1 Replies
Login or Register to Ask a Question