Guest corfuitl Posted May 30, 2014 Posted May 30, 2014 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... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.