![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to filter out some paragraphs in a file | cnlhap | Shell Programming and Scripting | 7 | 08-19-2008 12:03 PM |
| naming variables with variables | Allasso | Shell Programming and Scripting | 2 | 06-27-2008 07:45 AM |
| how to sort paragraphs by date within a file | nabmufti | Shell Programming and Scripting | 1 | 02-13-2008 02:33 PM |
| how to extract paragraphs from file in BASH script followed by prefix ! , !! and !!! | nabmufti | Shell Programming and Scripting | 6 | 02-09-2008 05:32 PM |
| smitty, remove user, remove directory as well.. | yls177 | UNIX for Dummies Questions & Answers | 2 | 11-10-2002 11:43 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using sed to remove paragraphs with variables
Hi everyone,
I have a file with multiple entries and I would like to remove the ones that contain either /A"> or /A/, where A can be any letter of the alphabet. Here's an example of the entries: <Topic r:id="Top/World/Fran">So, in this case, I want to have a new file that does not keep the last two entries as the first contains /A"> and the second contains /B/. I have tried with the following code, but it removes everything! #!/bin/sh # Removes topics that begin with a certain value inputFile=$1 tempFile=$inputFile.tmp # A number of indexing categories exist that have to be removed ALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZ" n=0 while [ $n -lt ${#ALPHABET} ] do sed -n '/\/${ALPHABET:n:1}\">/,/<\/Topic>/!p' $tempFile.start > $tempFile.end mv $tempFile.end $tempFile.start sed -n '/\/${ALPHABET:n:1}\//,/<\/Topic>/!p' $tempFile.start > $tempFile.end mv $tempFile.end $tempFile.start n=$(( $n + 1 )) done Can anyone out there please help? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The following works for ksh93
Code:
#!/bin/ksh93 while read line do [[ "$line" = ~(E)(\/[[:alpha:]]\/|\/[[:alpha:]]\"\>$) ]] || print $line done < file exit 0 Code:
<Topic r:id="Top/World/Fran"> <catid>476</catid> <link r:resource="http://fr.news.yahoo.com/"/> <link r:resource="http://news.google.fr/"/> <link r:resource="http://actualite.free.fr"/> </Topic> <Topic r:id="Top/World/Fran/Act/A_la_Une"> <catid>32293</catid> <link r:resource="http://www.pluralworld.com/"/> <link r:resource="http://www.webdopresse.ch/"/> </Topic> <catid>32069</catid> </Topic> <catid>32069</catid> </Topic> |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|