Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad delimiter in Bash shell

Tags:

bash

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?

like image 383
Naftaly Avatar asked Aug 15 '14 00:08

Naftaly


1 Answers

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>
like image 126
Warwick Avatar answered Sep 20 '22 19:09

Warwick