T
T
Thomas Storm2015-12-02 18:27:47
linux
Thomas Storm, 2015-12-02 18:27:47

How can I force the script to ignore lines starting with #?

Hello!
There is a script that does this:

#!/bin/bash

while read line
do
echo "This is a line" $line
done < lines.txt

And there is such a file lines.txt
#This is a line text
#blah blah
line1
line2
#line3
line4 six etc

Question - how in this script to make lines starting with a pound sign ignored and echo outputs only uncommented lines?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
protven, 2015-12-02
@v_sadist

Is it important for you to solve this with a "script"? Your wording solves the problem
grep -v '^#' <filename>

S
Saboteur, 2015-12-02
@saboteur_kiev

#!/bin/bash
while read line
do
 if ; then echo "This is a line" $line; fi
done < lines.txt

I
Igor, 2015-12-02
@fredyk

#!/bin/bash
egrep -v "^#" ./lines.txt | while read line
do
echo "$line"
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question