Reading lines in a file and avoiding lines with # with Bash

后端 未结 10 2044
清歌不尽
清歌不尽 2020-12-03 06:47

I tried this:

file=\"myfile\"
while read -r line
do
    [[ $line = \\#* ]] && continue
    \"address=\\$line\\127.0.0.1\"
done < \"$file\"
         


        
10条回答
  •  一向
    一向 (楼主)
    2020-12-03 07:39

    It has 3 parts. Please read each to understand clearly

    1. To remove # line ----- awk -F'#' '{print $1}' t.txt
    2. To remove a blank line created by # ---- awk 'NF > 0'
    3. To print in required format. ------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
    

提交回复
热议问题