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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:21:27+00:00 2026-05-13T10:21:27+00:00

I have a variable with the contents eth0 eth1 bond0, is there a way

  • 0

I have a variable with the contents “eth0 eth1 bond0”, is there a way using sed or a similar tool to move anything matching bond.* to the beginning of the line?

  • 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-13T10:21:28+00:00Added an answer on May 13, 2026 at 10:21 am

    Using nothing but Bash:

    $ var="eth0 eth1 bond0"
    $ [[ $var =~ (.*)\ (bond.*) ]]
    $ var="${BASH_REMATCH[2]} ${BASH_REMATCH[1]}"
    $ echo "$var"
    bond0 eth0 eth1
    

    Edit:

    This version handles multiple occurrences of “bond” anywhere within the string:

    var="eth0 bond0 eth1 bond1 eth2 bond2"
    for word in $var
    do
        if [[ $word =~ bond ]]
        then
            begin+="$word "
        else
            end+="$word "
        fi
    done
    var="$begin$end"
    var="${var%* }"    # if you need to strip the trailing space
    echo "$var"
    

    Output:

    bond0 bond1 bond2 eth0 eth1 eth2
    

    Edit 2:

    Here is a sed version that is specific to the string “bond” followed by one or more digits rather than allowing any word that begins with “b”:

    $ echo "eth0 bond0 eth1 bond1 eth2 bond2" | 
    sed 's/\<bond[[:digit:]]\+/\n&\n/g; s/ //g; :a; s/\(.*\)\n\(bond[[:digit:]]\+\)/\2 \1/;ta; s/\n/ /g'
    bond0 bond1 bond2 eth0 eth1 eth2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a variable containing a string, is there a way that I
If I have a variable containing an unescaped dollar sign, is there any way
Say you have a variable called hotelPropertyNumber . The contents will always be a
I have the contents of a web page assigned to a variable $html Here's
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I have a variable in JavaScript that contains the contents of an html textarea.
I have a variable with the following contents: a b c d e f
I have a simple form which accepts a Title and a Contents variable from
Suppose i have variable a with contents 123 and variable b123 with some text
I would like to declare a variable 'XMLOutput' and have it produce the contents

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.