I want to read a file line by line and exclude the lines that are beginning with special characters. The below code is working fine except when the line starts with hyphen (-) in the file.
for TEST in `cat $FILE | grep -E -v '#|/+' | awk '{FS=":"}NF > 0{print $1}'`
do
.
.
done
How should the grep statement be modified to ignore the line starting with hyphen?
for TEST in `cat $FILE | grep -E -v '#|/+' | awk '{FS=":"}NF > 0{print $1}'`
The thing is that grep does not need cat. grep pattern $FILE can read the file for itself.
awk does not need cat or grep. awk can exclude as well on its own.
awk '$0 !~ /pattern to exclude/ {action}' $FILE
As an example if you want to exclude all these character in the beginning of a line: `#/-+'
Thanks for your quick response. My requirement is different.
The file contains text as follows.
#test
+abc
-xyz
real
The for loop has to read the file line by line and pass the string in each line to the do loop. While reading each line in the file, if the line starts with # or + or - that line should be ignored.