I'm trying to iterate over few lines of bash script and echo all the non comment lines.
Within my loop I have the following command:
echo $line | cut -d" #" -f1
However the interpreter throws at me the following error:
cut: bad delimiter
What I did wrong?
As mentioned in the comments, the -d
parameter to cut
expects only one character. try using nawk
instead for your example:
echo $line | nawk 'BEGIN {FS=" #" } ; { print $1 }'
Or to just print lines that don't begin with a " #", use grep
:
grep -v " #" <file>
Or to print only lines that begin with a hash, or just white space and a hash, I'd use Perl:
perl -n -e 'unless (/(\S+)*#/) {print}' <file>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With