I think that you are mixing in the syntax for the find command. The -e option allows you to enter more than one sed command. For example, suppose that you want to change every occurance of the word 'furquan' to 'Furquan' in a document, and also remove all blank lines.
sed -i -e 's/furquan/Furquan/g' -e '/^$/d' document
This is the same as having a sed scripts "changes.sed" with the contents:
You would call this script like: sed -f changes.sed document
For some types of editing with sed, you have to use branches, and so you will need a sed script. Using a single
sed command with -e is best for simple changes.
I'll give you an example. Suppose that you use k3b to back up files in /home/username/Documents/ and you want to get rid of them. If you unzip the .k3b file you saved there will be a "mimetype" file and a "maindata.xml" file.
Examining the contents, you notice that the full pathname for each file is included in this document, but that the lines look like:
So you would like to A) remove all lines that don't match this pattern and B) remove the <url> and </url> part. So only 2 sed commands are necessary and you can put them in the same sed command and pipe the output to xargs.
sed -e '/^<url>/!d' -e 's/^<url>\(.*\)<\/url>/\1/' maindata.xml | tr '\n' '\000' | xargs -0 rm
The first command deletes all lines that don't start with '<url>'. The second command removes the <url> and </url> tags. The <url> and <\/url> parts in the search command serve as anchors, while the \(.*\) is a wild card that saves the contents in the middle. The \1 recalls the pattern found in the replace section of the sed substitute 's' command. The tr command replaces new-lines with null characters to make it easier to handle filenames that contain spaces.
The -e option is also used by the grep command. Suppose that you use the "locate" command but several screens are displayed. You can remove lines by piping the output through "grep":
locate pattern | grep -v -e pattern1 -e pattern2 -e pattern3
This way, you can press the up arrow, and keep adding patterns until you have the response pruned to how you want it.
Last edited by jschiwal; 03-04-2006 at 01:45 AM.