Hello!
I am trying to make a script that would extract information from a text file. The problem is that the text file has double linebreaks (Not sure if that's the right name... in a text editor, typing "Return" twice).
I did this:
Code:
#!/bin/bash
if [ $1 ] && [ $2 ]; then
if [ -e $2 ]; then
rm $2
fi
while read sample1
do
if [ ${sample1:0:2} = 'mc' ]; then
echo $sample1 >>$2
fi
done< $1
else
echo usage $0 [ infile ] [outfile]
fi
Every time it encounters an empty line, it sends the following annoying message:
Quote:
./wiki2txt.sh: line 9: [: =: unary operator expected
How could I get rid of it?
Thank you in advance
EDIT: The infile has the following structure:
Quote:
== Group B ==
=== info ===
faefaefasdfaefsef
adfasefasefasfs
asefaefsefsdfefsfe
asfaefsefsfsfefsefseu
If the file doesn't have the equal signs, nothing happens. If there are equal signs and no double space, nothing happens. But together, they send me the said error.