LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help this to make this sed efficient plz (https://www.linuxquestions.org/questions/programming-9/help-this-to-make-this-sed-efficient-plz-16859/)

doublefailure 03-23-2002 03:03 AM

help this to make this sed efficient plz
 
hi..
i'm a newbie to sed..

i'm gonna run this script on really really big file
(almost 1gig)

i think it should be really efficient
could u guys help me out?

thankyou !!

--------------------------------------------
#! /bin/bash
inputfile=$1

sed -e 's/<Topic r:id=\"//g' $inputfile |
sed -e 's/\">$//g' |
sed -e 's/\"\/>$//g' |
sed -e 's/<tag catid=\"//g' |
sed -e 's/^\".*//g' |
sed -e 's/<d:Title.*$//g'|
sed -e 's/<link r:.*$//g' |
sed -e 's/<\/Topic>//g' |
sed -e 's/<ExternalPage about\=\"//g' |
sed -e 's/<d:Description>//g' |
sed -e 's/<\/d:Description>//g' |
sed -e 's/<\/ExternalPage>//g' |
sed -e 's/^$//g' |
#sed -e 's/^Top.*\n$//g' |
awk '{
if ( $0 ~ /^Top/ )
printf("%s ", $0)
else
print $0
}' |

sed -e '/^$/d'
------------------------------------------

thank you!

Mik 03-25-2002 07:57 AM

I don't think it's that inefficient. You are passing the data through pipes so it will just have to read the file from disk once. You just need to add something like "> newfile" to the end. Because the way you have it now you'll just get everything on stdout. However you will need an extra gig free to write the newfile.
You can run multiple commands with one sed call though which might speed things up a bit.

Ex:
cat numbers | sed -e '/one/two/' -e '/three/four/'


All times are GMT -5. The time now is 06:00 AM.