Reputation: 2206
sed 's@.*/.*\.@.@'
The command is part of a larger command to find all file extensions in a directory.
find . -type f -name '*.*' | sed 's@.*/.*\.@.@' | sort | uniq
I understand that find
returns all files with an extension, I understand that sed returns just the extensions and then sort/uniq are self-explanatory.
At first, I was confused about the @
symbol, but my best guess now guess is that it is part of Regex.
What really confuses me is a can't figure how it explicitly works, and the closest matching syntax I can find in a manual is s/regexp/new/
which still doesn't match the syntax of the command.
Upvotes: 1
Views: 114
Reputation: 223043
In the s/regexp/replacement/
syntax, the /
can be replaced by any other character, such as ,
, :
, @
, etc. This is very useful if your regexp itself contains /
characters, such as your example of .*/.*\.
.
Your command could be simplified a bit, though:
find . -type f -name '*.*' | sed 's/.*\././' | sort -u
Here, I simplified the regexp so that it no longer contains a /
character.
Upvotes: 4