Thank you again.
Dave, your suggestion to add the optional argument to
read was just what I had missed.
In the script I was trying to set two variables from each
line of data and then run a cp(1) command for every iteration using
the two variables as filename arguments.
To set the first variable I used cut(1) once as a filter. For the
second variable I called cut again two more times in a pipe. What
confused me was that the first and the third filters gave me most
of the output I expected.
#!/bin/bash
while read -r; do
second_name="$(echo "$REPLY" | cut -d\" -f4)"
first_name="$(echo "$REPLY" | cut -d\\ -f4 | cut -d\" -f1)"
echo "cp $first_name $second_name"
# cp "$first_name" "$second_name"
done <example2.txt
#EOF
bash-4.2$ ./my_script.sh
cp 01-song_title.ogg D_E1M1
cp 02-song_title.ogg D_E1M2
cp 03-song_title.ogg D_E1M3
cp 04-song_title.ogg D_E1M4
bash-4.2$
example2.txt [4 line file]:
Music { ID = "e1m1"; foo = "D_E1M1"; Ext = "rel\path\to\01-song_title.ogg"; }
Music { ID = "e1m2"; bar = "D_E1M2"; Ext = "rel\path\to\02-song_title.ogg"; }
Music { ID = "e1m3"; bas = "D_E1M3"; Ext = "rel\path\to\03-song_title.ogg"; }
Music { ID = "e1m4"; foo = "D_E1M4"; Ext = "rel\path\to\04-song_title.ogg"; }
Output of the same script without the -r switch:
bash-4.2$ ./my_script.sh
cp Music { ID = D_E1M1
cp Music { ID = D_E1M2
cp Music { ID = D_E1M3
cp Music { ID = D_E1M4
bash-4.2$