0

I've got a command that I am trying to understand. Main issue is that the SED command doesn't line up with any examples I've seen before. I don't understand why

find . -name *_<templateName>_*|sed 's#.*/##' > wc_uDriveFiles<monYYYY>.txt 
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
Tino
  • 11
  • 3
  • 1
    Examples usually use / as the delimiter but you can use ANY character. In your example the delimiter is #. So your sed command replaces stuff followed by a slash with nothing (effectively deleting it) – Jerry Jeremiah Nov 04 '20 at 00:25
  • @Jerry that makes sense. Thanks so much! – Tino Nov 04 '20 at 00:38
  • Note that the first non-option argument is treated as a script text if, and only if, no other script is passed (by -e (script text) or -f (script file)). The man page is pretty good these days. – o11c Nov 04 '20 at 00:42
  • Note: If you want to match a line that contains a `/` you can either use `sed '/\//' file` or `sed '\#/#' file`. The second example changes the regexp delimiter to `#` i.e. to change the delimiter for a regexp address, precede that character with `\ ` e.g. `sed '\@/@' file` will also match a `/`. – potong Nov 04 '20 at 06:08

1 Answers1

0

sed's s command performs search-and-substitute. The following letter (here #) separates pattern, replacement and options. Note that regex pattern is taken greedy.

An example should clarify how it works

$ cat file.txt
abc
ab/c
a/b/c

$ sed 's#.*/##' file.txt
abc
c
c

So, text up to and including the last slash, if any, gets dropped

Frank Neblung
  • 3,047
  • 17
  • 34