LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-25-2006, 08:41 AM   #1
slack66
Member
 
Registered: Jul 2003
Location: manila
Distribution: slackware 8 to 9
Posts: 199

Rep: Reputation: 30
sed question?


hi!
i just want to know how do i extract the content of a file... ex. i have a files named "mydoc.txt and the content are the ff.

/projects/disk1/aaa.doc
/projects/disk2/bbb.doc
/projects/disk3/ccc.doc
/projects/disk4/ddd.doc

and i want to create new file that content only

/projects/disk1/ccc.doc

extrating only the word /projects/disk1/ccc.doc
using SED. thk adv
 
Old 07-25-2006, 08:49 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
you wouldn't use sed for that, doesn't make sense. you'd grep for it instead. if you really think that you need sed then i'd think your example file is not describing your problem for you well enough.
 
Old 07-25-2006, 09:17 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
if you want to use sed you can do
Code:
sed -n /pattern/p file
OR to print only the lines not matched by the pattern you can do
Code:
sed -n /pattern/!p file
 
Old 07-25-2006, 07:26 PM   #4
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Based exactly on what you are asking in the question:
Code:
grep "/projects/disk1/ccc.doc" mydoc.txt > newfile.txt
You can throw in the -i switch for case insensitive, or -v for antipattern, or pipe it through futher commands, etc. etc.
 
Old 07-26-2006, 06:19 AM   #5
slack66
Member
 
Registered: Jul 2003
Location: manila
Distribution: slackware 8 to 9
Posts: 199

Original Poster
Rep: Reputation: 30
yes i know that i can use grep to filter the word that i want to get but the problem is that the word /projects/disk1/ccc.doc is dynamicaly changing. it means that its time i run the program it will not be the same words again. ex.

/projects/disk1/aaa.doc
/projects/disk1/bbb.doc
/projects/disk1/ccc.doc
/projects/disk1/ddd.doc

the next time i run the program again it will be

/projects/disk1/fff.doc
/projects/disk1/ggg.doc
/projects/disk1/hhh.doc
/projects/disk1/iii.doc


i just want to get the third line "/projects/disk1/hhh.doc"
i want to extract according to number of line. (line #3 or line #1)
 
Old 07-26-2006, 06:36 AM   #6
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
You should have told that you want to extract that line by the line number. You can get line 3 using
Code:
sed -n '3p'
 
Old 07-26-2006, 06:41 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
do you mean you need to get a line by its number?

Code:
sed -n 3p mydoc.txt
Edit: sorry spirit receiver i didn't see your post. i though it was slack66. damn i need to sleep.

Last edited by konsolebox; 07-26-2006 at 06:43 AM.
 
Old 07-26-2006, 07:47 AM   #8
slack66
Member
 
Registered: Jul 2003
Location: manila
Distribution: slackware 8 to 9
Posts: 199

Original Poster
Rep: Reputation: 30
oh sorry for not giving the detail that iwant to be done
any thank you guys! for helping
that y i love linux
 
  


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
sed question krock923 Programming 2 04-30-2006 10:36 PM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 01:34 AM
sed question sphynx Programming 6 04-28-2004 07:25 PM
little sed question freelinuxcpp Linux - Software 3 01-20-2004 08:36 AM
A question on 'sed' Barbarian Programming 4 04-11-2002 11:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:07 PM.

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