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

  • Home
  • SEARCH
  • 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 7066929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:08:24+00:00 2026-05-28T05:08:24+00:00

From ant, we want to extract a line from an old /etc/shadow file, capturing

  • 0

From ant, we want to extract a line from an old /etc/shadow file, capturing the line for a specific user name, such as “manager”. This is part of a backup/restore operation. What we used previously was not specific enough, so it would match users like “mymanager”, so we tried to tighten it down by anchoring the start of the string to beginning of the line (typically “^”). This definitely did not work as we expected.

How can we anchor so that we get an exact match for a username? — answered below.

First attempt, which gave the wrong result if we had a user of “mymanager” in the /etc/shadow file copy:

<loadfile property="oldPasswords" srcFile="${backup.dir}/shadow"/>
<propertyregex property="manager.backup" input="${oldPasswords}"
    regexp="(manager\:.*)" select="\1" casesensitive="true" />

Second attempt, which failed because “^” is not interpreted in the normal regular expression way by default:

<loadfile property="oldPasswords" srcFile="${backup.dir}/shadow"/>
<propertyregex property="manager.backup" input="${oldPasswords}"
    regexp="^(manager\:.*)" select="\1" casesensitive="true" />

Kobi suggested adding -> flags=”m” <- which sounded good but ant reported that the flags option is not supported by propertyregex.

The final, successful, approach required inserting “(?m)” at the beginning of the regexp: That was the essential change.

<propertyregex property="manager.backup" input="${oldPasswords}"
    regexp="(?m)^manager:.*$" select="\0" casesensitive="true" />

The regexp with propertyregex appears to follow the rules in this documentation of regular expressions in Java (search for “multiline” for example): http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

Check the above document if you have similar questions about how to make propertyregex and regexp do what you want them to do!

THANKS! Solved.

Alan Carwile

  • 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-28T05:08:24+00:00Added an answer on May 28, 2026 at 5:08 am

    I think the m(ultiline) flag is what you want to use and will give the start-of-line anchor the right behavior. It’s possible to change flags within the regular expression with the syntax (?<flagstoturnon>-<flagstoturnoff>). So in your case, adding (?m) to the start of the regular expression (before the caret) should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extract the version number from a file name generated outside of
I want to run a VBScript file from an Ant script. How can I
I want to execute a command from an Ant buildfile, for each file in
I use Ant to build Delphi applications (called from CruiseControl). I want ant to
I need to modify a (xml-)file from Apache Ant. loadfile task allows to load
I've been running the built-in Ant from the command line on a Macintosh (10.5.5)
I come from an ant background, and I'm starting to use msbuild. I want
I want to execute a build.xml (Ant buildfile) from using GMaven (Maven Plugin for
I'm trying to run Junit test from my ant build.xml file. I read here
I need to increment a number in a source file from an Ant build

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.