Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6826679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:10:34+00:00 2026-05-26T22:10:34+00:00

I tried this: file=myfile while read -r line do [[ $line = \#* ]]

  • 0

I tried this:

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

This code doesn’t avoid the lines that begin with comments. Even if I don’t have any comments, dnsmasq tells that there are errors.

Its going to be a dnsmasq conf file, and it will read and insert domain names like so: address=\mydomain.com\127.0.0.1.


EDIT:1

Input file:

domain1.com
domain2.com
domain3.com
#domain4.com
domain5.com

Output should be:

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

I will drop the script in /etc/dnsmasq.d/ directory so that dnsmaq.conf can process it when dnsmasq is started.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:10:35+00:00Added an answer on May 26, 2026 at 10:10 pm

    It’s safer to use [[ "$line" = "\#*" ]]

    Btw, address="\\${line}\\127.0.0.1"

    UPD:

    If I’ve understand you right you need to change every uncommented domains to address=\domain\127.0.0.1. It could be done fast and easy with sed, there is no need in bash-program.

    $> cat ./text
    domain1.com
    domain2.com
    domain3.com
    #domain4.com
    domain5.com
    
    $> sed -r -e 's/(^[^#]*$)/address=\/\1\/127.0.0.1/g' ./text2
    address=/domain1.com/127.0.0.1
    address=/domain2.com/127.0.0.1
    address=/domain3.com/127.0.0.1
    #domain4.com
    address=/domain5.com/127.0.0.1
    

    If you need to remove commented lines, sed can do it too with /matched_line/d

    $> sed -r -e 's/(^[^#]*$)/address=\/\1\/127.0.0.1/g; /^#.*$/d' ./text2 
    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
    

    UPD2: if you want to do all that stuff inside the bash script, here is your code modification:

    file="./text2"
    while read -r line; do
        [[ "$line" =~ ^#.*$ ]] && continue
        echo "address=/${line}/127.0.0.1"
    done < "$file"
    

    And it’s 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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this code to open a file in Python: f = open("/Desktop/temp/myfile.txt","file1") It
I tried this aproach without any success the code I'm using: // File name
I tried to read a file in a view like this: def foo(request): f
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
I have a problem I tried to retrieve a file with this code: <?php
Does file_get_contents maintain line breaks? I thought it did but I have tried this:
I have a root view controller with no nib file, I tried adding this
I want to load a local file, example.pages in UIWebview. I tried with this
I've tried putting (setq term-setup-hook 'vip-mode) in my .emacs file but this only seems
I tried to create a file using Oracle UTL_FILE.FOPEN command but i get this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.