LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-20-2006, 03:59 AM   #1
Fond_of_Opensource
Member
 
Registered: May 2006
Posts: 55

Rep: Reputation: 15
Exclamation 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

Last edited by Fond_of_Opensource; 11-20-2006 at 04:07 AM.
 
Old 11-20-2006, 04:47 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,732

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
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.

Last edited by bathory; 11-20-2006 at 04:51 AM.
 
Old 11-20-2006, 05:57 AM   #3
uncle-c
Member
 
Registered: Oct 2006
Location: The Ether
Distribution: Lubuntu 14.04 LTS, Kali
Posts: 297

Rep: Reputation: 30
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

Last edited by uncle-c; 11-20-2006 at 06:03 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
Sed help please nazs Programming 21 04-20-2005 06:59 PM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration