I have not found a way to use this regex expression - .+?(?=,) in the sed command to extract part of this string (using Lookbehind of the first instance of character).
In plain english I want to extract the part of the string that lies before the first comma. As I'm planning to extract in the future the specific filename of the string, I cannot rely on the cut command (I will have to eventually use sed command) , :-
name='ERROR 1: /home/rphillips/Desktop/empties/BN23_2303.tif, band 1: Failed to compute statistics, no valid pixels found in sampling.'
These are the variations that I've used including a test - sed 's/band/rose/' which worked. However the other variations (shown below) that I've used gave spaces as outputs.
while read -r line; do
name="$line"
echo $name
#file_path=$(echo $name | cut -d "," -f 1)
#file_path=$(echo $name | sed -e '/s\/.+?(?=,)///')
#file_path=$(echo $name | sed 's/band/rose/')
file_path=$(echo $name | sed '/s\/.+?(?=, )///')
#file_path=$(echo $name | grep -P '.+?(?=,)')
#file_path=$(echo $name | sed
#file_path=$(echo $name | awk '/.+?(?=,)/{print $name}'
echo $file_path
done < "$filename"
Expected Result - ERROR 1: /home/rphillips/Desktop/empties/BN25_2303.tif
Actual Results - 'lots of spaces'
I've also noticed that the regex expression that I've used have different 'matches' according to the Regex101 Website depending whether I'm using Firefox on Windows or Ubuntu 16.04LTS
Windows - https://regex101.com/r/WWGf8F/1 Ubuntu - https://regex101.com/r/NpL2Oa/1
I'm not sure if this is causing the expression not to be recognized by sed -e
?
I have used these references to for the different expressions used in the code above
https://likegeeks.com/regex-tutorial-linux/
How to match "anything up until this sequence of characters" in a regular expression?