Using sed to grab filename from full path? -
I'm new to sed, and the output of the search
must be just holding the file name. I have to get the output full path for the second part of my script, but I want to print the file name without the path. I need a line from the line starting from the beginning , not the end In English, I want to match, "." The first group of characters that ends with "/" is my attempt that does not work:
ryan @ fizz: ~ $ find / home / ryan / desktop / test / -type f -name \ *. Txt / home / ryan / desktop /test/two.txt/home/ryan/Desktop/test/one.txt ryan @ fizz: ~ $ find / home / ryan / desktop / test / -type f -name \ *. Txt | Sed s: ^. * / [^ *. Txt] :: g esktop / test / two.txt ne.txt
Here I think the output is:
Two. Txt one.txt
OK, so the given solution answered my original question, but I think I said it wrong. I do not want to kill the previous row with the suffix of the file, I am searching. So, if more clear, then the following:
bash $ new_mp3s = \ 'MP3 directory type f -name \ *. MP3 & amp; Amp; Cp -rfv $ new_mp3s dest `/mp3dir/one.mp3 '- & gt; `/dest/one.mp3 '` /mp3dir/two.mp3' - & gt; I want to: bash $ new_mp3s = \ 'MP3 directory type f -name \ *. MP3 & amp; Amp; Cp -rfv $ new_mp3sDest | Sed ??? `One. MP3 '- & gt; `/ Dest '` two.mp3' - & gt; `/ Dest '
Sorry for the confusion, the first part of what I am trying to do in my original question is included in it.
Edit 2: What I'm doing here:
DEST = / tmp & amp; & Amp; CP-RFV `Search / MP3 DIR-Type F-Name '*. Mp3 `$ DEST | Sed -e's: [^ \ \]. * / :: '-e "s: $: -> $ DEST:"
This is not quite what I need though. Instead of setting the destination directory to a shell variable instead, I would like to replace the first sed
operation, so that only cp
changes in output before each "->" line That's because I still have to work with the second part of the second part of the cp
output. Edit 3rd: Regex is still working, but the following works by using Perl:
cp -rfv `find / mp3Dir -type f -name \ *. Mp3 / tmp | Pearl -P "S:. * / (.mp3). * \` (. * /) *. Mp3 \ '$: \ $ 1 - & gt; \ $ 2: "
I want to do it in Cal.
Something like this should do the trick:
yourdir - Type f -name \ *. Txt | Sed's /.**/// '
Or, slightly obvious,
yourdir -type f -name \ *. Find Txt Sed:. * / :: '
Comments
Post a Comment