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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:44:00+00:00 2026-06-15T19:44:00+00:00

my situation is this – I have a file: this line(5) that line(6) another

  • 0

my situation is this – I have a file:

this line(5)
that line(6)
another line(9)
one more(88)
last line(156)

I need to change the values in brackets from that to:

this line(1)
that line(2)
another line(3)
one more(4)
last line(5)

Basically, make the values ordered starting from 1.

Now, here’s my code:

#!/bin/bash

FILE=$1
COUNT=0
echo "Working with $FILE"

if [ -f $FILE ]; then
while read -r line; do 
    echo ${line/\([0-9]{1,3}\)/\($COUNT\)};
     let COUNT++;
  done < $FILE
else
  echo "File does not exist!"
fi

Here’s what I get:

this line(5))/(0)}
that line(6))/(1)}
another line(9))/(2)}
one more(88))/(3)}
last line(156))/(4)}

What am I doing wrong? How can I specify in regex a number of artbitrary length?

Much appreciated.

  • 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-06-15T19:44:01+00:00Added an answer on June 15, 2026 at 7:44 pm

    change your echo line to this:

    echo ${line%%\([0-9]*\)}\($COUNT\)
    

    Edit: The pattern replacement versions works as well, assuming there isn’t parentheses with numbers anywhere else in the line – to use the pattern replacement and make sure that it only looks at the end of the line, use a % char after the first / separator, like so:

    echo ${line/%\([0-9]*\)/\($COUNT\)}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this situation: $(#button).toggle(function(){ $(#window).animate({top:'0%'},1000); },function(){ $(#window).animate({top:'-100%'},1000); }); but I need change it
I have this situation that I need to let users define decisions based on
I have this situation: An object that it's observable and another object that it
Situation is this: I have a table for staff and another one for course.
The Situation (Ignore this it is boring): I have reports that I created using
In this situation, I have created a zip file containing search result files, and
I have this situation where I need to modify the insert command after is
Consider this situation where we have one product Laptop adapter and its stock as
I have this situation where I declare inside my main class a function that
I have this situation were I need to include Persons inside a Group. For

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.