Reputation: 33
I'm working on a bash shell script, which goes through a folder and eventually makes new directories based off file names. Now I want to go through each file and strip away unwanted slashes of the path and ignore the fileextension before making a new directory. To test this, I'm echoing my file like this:
#!/bin/sh
cpath=`pwd`
for file in $cpath/*;do
echo $file | grep -E '(?!.*/).+(?=\.)'
done
But grep filters out everything and I get no output. I worked out the regex with RegExr http://gskinner.com/RegExr/?2vu6b
Negative lookahead to match the last slash and positive lookahead matching the last dot.
Upvotes: 3
Views: 516
Reputation: 77105
I am not sure if Negative lookahead is a part of Extended RE. But you can do something like this -
#!/bin/bash
for file in $PWD/*; do
basename "${file%.*}"
done
Upvotes: 2