|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to write a script that will parse a listing that I get from grep. The problem I am running into is that I cannot figure out how to get sed to remove a / from the line. I would appreciate any pointers on looking for the / or removing a whole path such as /usr/share/ or some like listing.
-SJ |
|
#2
|
|||
|
|||
|
sed "s/\///;"
|
|
#3
|
|||
|
|||
|
you might want to check out commands basename and dirname
|
|
#4
|
|||
|
|||
|
satyap is correct, that is the elegant way to do it
(only the ';' is superflous (in this exemple)) and pay attention " is not ' an other way, tell sed to use an other field-sep, so s/abc/qwe/g is the same as s,abc,qwe,g but now 'abc' could be 'ab/c' do you see ? an other Q is: why sed the output of grep ? why not just let sed do the whole job ? (it sure can it!!) |
|
#5
|
|||
|
|||
|
Re: sed help needed
Reason I a, using grep to get initial out is that I am generating a PPD file and model name lising on the fly by using grep and the ModelName as my search term. This keeps me from having to update a file manually with the name of a model and the associated PPD.
Ok, the "sed "s/\///;" option seems like it should do the trick, but is there anyway to do it with a regexp?? Dont mean to be be choosy, but I thought about it afterwards and now I cant seem to let it go. I will however use the initial solution as soon as I get into office in the morning |
|
#6
|
|||
|
|||
|
the reason why you use grep and sed is
you never checked: grep can a lot and sed a lot more. so a well constructed grep OR sed easy can replace a grep|sed what is 's/\///' when NOT a regexpr ??? |
|
#7
|
|||
|
|||
|
Quote:
I guess I may not have clearly stated what I was trying to accomplish. What I am looking at now is having to have 's/\///' for each "/" character that I want to remove, I was hoping there may have been a more elegant solution to remove multiples at the same time instead of a single, or remove a "/" followed by a text string. PS if you know how to get sed to seach each file in a specified directory for a particular string and and return the entire line I'm game for knowing. I'm a newbie to sed so please forgive my ignorance of its capabilities |
|
#8
|
|||
|
|||
|
sed "s/\///g"
(see, guggach, I removed the ; :-) ) |
|
#9
|
|||
|
|||
|
Quote:
I appreciate it tons..... |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > sed help needed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|