You're on the right track, but there are problems with your code:
- Remove the spaces around
=
in theFILE =
line - your script will break otherwise. - Your
while
statement is missing ado
line (or; do
appended to thewhile
line directly). - Instead of referring to variable
$FILE
in thedone
line, your passing the string literalFILE
instead - use"$FILE"
(the quotes are there to ensure that it works even with filenames that have embedded spaces and other chars. interpreted by the shell).
As for ignoring the optional character on the end of the line: simply adding another variable, as your code already does (charP
), is sufficient - it will then be assigned the remainder of the line, and you can just ignore it.
If we put it together, adding the code for ignoring comment lines, we get:
FILE='test.txt'
while IFS=' ' read -r numA numB numC numD charP
do
if [[ $numA != \#* ]]; then # ignore comment lines
# ... do something
fi
done < "$FILE"