How to extract string from filename
geoff at QuiteLikely.com
Wed Jul 29 11:30:04 UTC 2015
On Wed, 29 Jul 2015, Tony Baechler wrote:
> What I'm trying to do is extract the BBC PID from the downloaded files. It's
> a lower case alphanumeric string which starts with a letter and is eight
> characters. In my case, the first letter is always "b" or "p," so if I could
> use something like grep to just extract the first lower case letter followed
> by a number up to the next underscore, that would be good. I don't think
> grep will just print a matching phrase, only the matching line. Here are
> some example filenames:
You can use basename to get rid of the end.
$ basename Click_-_05_10_2010_p00b18gp_default.mp3 _default.mp3
You could then use cut with this youtput to get what ou want.
More information about the Blinux-list