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 183359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:06:07+00:00 2026-05-11T15:06:07+00:00

I’m getting totally lost in shell programming, mainly because every site I use offers

  • 0

I’m getting totally lost in shell programming, mainly because every site I use offers different tool to do pattern matching. So my question is what tool to use to do simple pattern matching in piped stream.

Context: I have named.conf file, and I need all zones names in a simple file for further processing. So I do ~$ cat named.local | grep zone and get totally lost here. My output is ~hundred or so newlines in form ‘zone "domain.tld" {‘ and I need text in double quotes.

  • 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. 2026-05-11T15:06:07+00:00Added an answer on May 11, 2026 at 3:06 pm

    I think what you’re looking for is sed… it’s a stream editor which will let you do replacements on a line-by-line basis.

    As you’re explaining it, the command `cat named.local | grep zone’ gives you an output a little like this:

    zone 'domain1.tld' { zone 'domain2.tld' { zone 'domain3.tld' { zone 'domain4.tld' { 

    I’m guessing you want the output to be something like this, since you said you need the text in double quotes:

    'domain1.tld' 'domain2.tld' 'domain3.tld' 'domain4.tld' 

    So, in reality, from each line we just want the text between the double-quotes (including the double-quotes themselves.)

    I’m not sure you’re familiar with Regular Expressions, but they are an invaluable tool for any person writing shell scripts. For example, the regular expression /.o.e/ would match any line where there’s a word with the 2nd letter was a lower-case o, and the 4th was e. This would match string containing words like ‘zone‘, ‘tone‘, or even ‘I am tone-deaf.‘

    The trick there was to use the . (dot) character to mean ‘any letter’. There’s a couple of other special characters, such as * which means ‘repeat the previous character 0 or more times’. Thus a regular expression like a* would match ‘a‘, ‘aaaaaaa‘, or an empty string: ”

    So you can match the string inside the quotes using: /'.*'/

    There’s another thing you would know about sed (and by the comments, you already do!) – it allows backtracking. Once you’ve told it how to recognize a word, you can have it use that word as part of the replacement. For example, let’s say that you wanted to turn this list:

    Billy 'The Kid' Smith Jimmy 'The Fish' Stuart Chuck 'The Man' Norris 

    Into this list:

    The Kid The Fish The Man 

    First, you’d look for the string inside the quotes. We already saw that, it was /'.*'/.

    Next, we want to use what’s inside the quotes. We can group it using parens: /'(.*)'/

    If we wanted to replace the text with the quotes with an underscore, we’d do a replace: s/'(.*)'/_/, and that would leave us with:

    Billy _ Smith Jimmy _ Stuart Chuck _ Norris 

    But we have backtracking! That’ll let us recall what was inside the parens, using the symbol \1. So if we do now: s/'(.*)'/\1/ we’ll get:

    Billy The Kid Smith Jimmy The Fish Stuart Chuck The Man Norris 

    Because the quotes weren’t in the parens, they weren’t part of the contents of \1!

    To only leave the stuff inside the double-quotes, we need to match the entire line. To do that we have ^ (which means ‘beginning of line’), and $ (which means ‘end of line’.)

    So now if we use s/^.*'(.*)'.*$/\1/, we’ll get:

    The Kid The Fish The Man 

    Why? Let’s read the regular expression s/^.*'(.*)'.*$/\1/ from left-to-right:

    • s/ – Start a substitution regular expression
    • ^ – Look for the beginning of the line. Start from there.
    • .* – Keep going, reading every character, until…
    • ' – … until you reach a double-quote.
    • ( – start a group a characters we might want to recall later when backtracking.
    • .* – Keep going, reading every character, until…
    • ) – (pssst! close the group!)
    • ' – … until you reach a double-quote.
    • .* – Keep going, reading every character, until…
    • $ – The end of the line!

    • / – use what’s after this to replace what you matched

    • \1 – paste the contents of the first group (what was in the parens) matched.
    • / – end of regular expression

    In plain English: ‘Read the entire line, copying aside the text between the double-quotes. Then replace the entire line with the content between the double qoutes.’

    You can even add double-quote around the replacing text s/^.*'(.*)'.*$/'\1'/, so we’ll get:

    'The Kid' 'The Fish' 'The Man' 

    And that can be used by sed to replace the line with the content from within the quotes:

    sed -e 's/^.*\'\(.*\)\'.*$/\'\1\'/' 

    (This is just shell-escaped to deal with the double-quotes and slashes and stuff.)

    So the whole command would be something like:

    cat named.local | grep zone | sed -e 's/^.*\'\(.*\)\'.*$/\'\1\'/' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are pywin32 available for 3.0. Python 3.1 was release… May 11, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer I just got programmatic expanding and collapsing of NSSplitView to… May 11, 2026 at 11:42 pm
  • Editorial Team
    Editorial Team added an answer It seems to me that the method you outlined in… May 11, 2026 at 11:42 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.