Jump to content

Recommended Posts

Guest corfuitl
Posted

Hi all

 

I am trying to write a bash script that will recognize a sequence of numbers and will replace them according an if statement.

 

Could you please let me know how to assign that number that is recognized according to a regex into a variable? For instance, if my txt file looks like:

 

Code:

Text text text 15 text text text

Text text text text text 7

….

I want to replace all the numbers that are >=16.

 

My code is :

 

Code:

while read line

do

number=$(echo $line | sed ‘s/[0-9][0-9]/g’)

 

if [ $number >=16 ]

then

number=$( sed ‘s/([0-9])([0-9])/\2\1/g’)

fi

echo $number

done <file.txt

 

I would appreciate your help.

 

Thanks

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...