LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed question? (https://www.linuxquestions.org/questions/linux-newbie-8/sed-question-467420/)

slack66 07-25-2006 07:41 AM

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:)

acid_kewpie 07-25-2006 07:49 AM

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.

konsolebox 07-25-2006 08:17 AM

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

Vgui 07-25-2006 06:26 PM

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.

slack66 07-26-2006 05:19 AM

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)

spirit receiver 07-26-2006 05:36 AM

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'

konsolebox 07-26-2006 05:41 AM

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.

slack66 07-26-2006 06:47 AM

oh sorry for not giving the detail that iwant to be done:)
any thank you guys! for helping:)
that y i love linux


All times are GMT -5. The time now is 04:41 AM.