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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:56:40+00:00 2026-05-31T17:56:40+00:00

Sorry for bumpy topic name (feel free to edit if you find more fitting

  • 0

Sorry for bumpy topic name (feel free to edit if you find more fitting title after looking at problem).
Code sample equals 1000 words, so here we go:

if [ "$REGEX" != "" ]; then
        find $TEST_DIR -type f -regextype posix-extended -regex '^.*(status|stderr|stdout)-captured$' |                                  
        grep -E $REGEX |
        awk '{print(""$1" "$1)}' | sed 's/-captured$/-expected/' | 
        while read -r line; do mv -f $line; done 
else
        find $TEST_DIR -type f -regextype posix-extended -regex '^.*(status|stderr|stdout)-captured$' |
        awk '{print(""$1" "$1)}' | sed 's/-captured$/-expected/' |
        while read -r line; do mv -f $line; done
fi

What code does is not all that important, I’d just like to find more elegant way to either use “grep -E $REGEX” or not. I thought that conditdonal aliases could do the job just like I’m used to from shell usage, but they does not work inside scripts.

I could put in a condition, but I fear performance impact from multiple evaluations.

Any way to make the code “more elegant”?

  • 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-31T17:56:41+00:00Added an answer on May 31, 2026 at 5:56 pm

    One simple way is to use ^ (which always matches: it means “start-of-line”, which every line has) if $REGEX is unset or blank:

    find $TEST_DIR -type f -regextype posix-extended -regex '^.*(status|stderr|stdout)-captured$' |
    grep -E ${REGEX:-^} |
    awk '{print(""$1" "$1)}' | sed 's/-captured$/-expected/' |
    while read -r line; do mv -f $line; done
    

    For that matter, you can combine it into the original find:

    find $TEST_DIR -type f -regextype posix-extended \
         -regex '^.*(status|stderr|stdout)-captured$' \
         -regex ".*${REGEX}.*" |
    awk '{print(""$1" "$1)}' | sed 's/-captured$/-expected/' |
    while read -r line; do mv -f $line; done
    

    and for that matter, you can merge all of the rest of your script into find as well:

    find $TEST_DIR -type f -regextype posix-extended \
         -regex '^.*(status|stderr|stdout)-captured$' \
         -regex ".*${REGEX}.*" \
         -exec bash -c 'file="{}" ; mv -f "$file" "${file%-captured}-expected"' \;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry the title isn't more help. I have a database of media-file URLs that
Sorry if this is a noob question, but All my code is error-free and
Sorry the title is not very descriptive but it is a tricky problem to
Sorry about the confusing title, I had a hard time describing the problem. I
Sorry the title is fuzzy, but I really coudln't come up with a fitting
Sorry if the title is poorly descriptive, but I can't do better right now
Sorry for the long question title. I guess I'm on to a loser on
Sorry I could not find this. $('div#loader').slideDown(fast).delay(1.5); Does not word as expected, I want
(sorry about the long title) I have a custom object Person, which in turn
Sorry for the non-descript title, but I'm having a hard way with words right

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.