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:) |
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.
|
if you want to use sed you can do
Code:
sed -n /pattern/p file Code:
sed -n /pattern/!p file |
Based exactly on what you are asking in the question:
Code:
grep "/projects/disk1/ccc.doc" mydoc.txt > newfile.txt |
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) |
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' |
do you mean you need to get a line by its number?
Code:
sed -n 3p mydoc.txt |
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 05:41 AM. |