View Full Version : bash formating a text file

March 15th, 2008, 12:42 PM
Hi all I've written a bash sript to parse some rss feeds into a text file that will hold the individual links, but I'm having a problem formating it correctly. The file contains links of varying lengths,



unfortunatly i cannot seem to remove the


from the end of each line is there any one liners that can do this ?

thanks dunryc

March 15th, 2008, 12:50 PM

sed -i "s/<\/link><guid//" <filename>

Replacing filename with the name of the file to be edited.

March 15th, 2008, 01:13 PM
thanks for the heads up smartbei that worked great :-)

March 15th, 2008, 07:20 PM
oh dear I'm stuck again sed grep seem so hard to under stand the syntax of these commands i now have a html file saved on disc with i wish to replace some words in, for example


to something like


but i cant get sed to handle the quotation mark correctly ! any one had any experience with this ??

March 15th, 2008, 08:52 PM
If you want to pass double quotes to sed then the easiest way to quote it in the bash shell is to use single quotes around the argument.
The shell will pass on all double quotes that appear within single quotes.
If you want to use / in your pattern or replacement you can use a different character as the delimiter so / won't need special backslash quoting.
This uses @ as the delimiter.

sed 's@src="/@src="http://www.test.co.uk/@' input.html

March 16th, 2008, 02:24 AM
but i cant get sed to handle the quotation mark correctly ! any one had any experience with this ??

other ways.

# awk 'BEGIN{OFS=FS="="}{$2="\"http://www.test.co.uk/arts/graphics/2008/02/24/bomoo124.jpg\""}{print}' htmlfile

or simple bash

while read -r line
case $line in
"src=") echo 'src="http://www.test.co.uk/arts/graphics/2008/02/24/bomoo124.jpg"'
done < "htmlfile"

March 16th, 2008, 04:43 PM
thanks for the heads up guys ill give it a try later dring the week when i get some time