I tried this:
file=\"myfile\"
while read -r line
do
[[ $line = \\#* ]] && continue
\"address=\\$line\\127.0.0.1\"
done < \"$file\"
awk '{ if ($0 !~ /^#/){printf "address=/%s/127.0.0.1 \n",$0}}' <your_input_file>
You can filter with awk
:
awk '!/^#/{print"address=/"$0"/127.0.0.1"}' file
[ "${line:0:1}" = "#" ] && continue
This takes the string, gets the substring at offset 0, length 1:
"${line:0:1}"
and checks if it is equal to #
= "#"
and continues looping if so
&& continue
http://www.tldp.org/LDP/abs/html/string-manipulation.html
Comment lines can and often do begin with whitespace. Here's a bash native regex solution that handles any preceeding whitespace;
while read line; do
[[ "$line" =~ ^[[:space:]]*# ]] && continue
...work with valid line...
done
Maybe you can try
[[ "$line"~="#.*" ]] && continue
Check the ~
in operand!
It has 3 parts. Please read each to understand clearly
awk -F'#' '{print $1}' t.txt
awk 'NF > 0'
awk '{print "address=/"$0"/127.0.0.1"}'
So Total Script Needed is,
**awk -F'#' '{print $1}' t.txt | awk 'NF > 0' | awk '{print "address=/"$0"/127.0.0.1"}'**
Output :
address=/domain1.com/127.0.0.1
address=/domain2.com/127.0.0.1
address=/domain3.com/127.0.0.1
address=/domain5.com/127.0.0.1