LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   using sed (https://www.linuxquestions.org/questions/linux-newbie-8/using-sed-503207/)

Fond_of_Opensource 11-20-2006 03:59 AM

using sed
 
hi,


the problm is :

cat myfile:

ABCD/xyz.html
ABCD/prs.html
ABCD/qty.html
-----
---------
-----

upto 1000+ lines


I want to take only the fields xyz, prs, qty etc and save it in another file. How to do it using sed?


sed -n '/\//,/html/p' pathname
______ is not working.....


pls help

bathory 11-20-2006 04:47 AM

I'm not a sed expert either, but something like this
Code:

sed 's/[ABCD/]*//;s/[.html]*$//' file > newfile
would do the job.
Take a look at this guide for more.

uncle-c 11-20-2006 05:57 AM

Your sed regexp won't work because it prints lines "inclusive " of the strings.
Probably easier to substitute the said strings with "BLANK" and then pipe the output to a new file.
This works and I'm sure someone with much more experience in Sed can come out with a shorter one liner.

sed -e 's/ABCD\///g' -e 's/\.html//g' file > stripped_file

Which is basically what bathory's sed script does.

Hope this helps.
Uncle


All times are GMT -5. The time now is 11:16 PM.