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

后端 未结 10 2034
清歌不尽
清歌不尽 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:40

    This could also be accomplished with 1 sed command:

    file="myfile"
    
    sed -i".backup" 's/^#.*$//' $file
    

    This will modify the file in-place (creating a backup copy first), removing all lines starting with a #.

提交回复
热议问题