

From the bash command shell, parse the numbers of a line
source link: https://www.codesd.com/item/from-the-bash-command-shell-parse-the-numbers-of-a-line.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

From the bash command shell, parse the numbers of a line
I have a log line that I am pulling from bash like:
There are 5 apples and 7 oranges
And I want to get the 5 and 7 into bash variables and am having problems doing so.
awk '{ print $3, $6 }' won't work due to the fact that their position might change, if there are bananas. Bonus points if the digits can be associated with their fruits.
Thanks in advance
and to get the fruits:
echo 'There are 5 apples and 7 oranges' | grep -o -E '[[:digit:]]+ [[:alpha:]]+'
Related Articles
Delete numbers from the beginning of a line in a string with PHP
How to remove the character from the numbers
How to classify (prioritize) values from the numbered check box form in PHP
Delete the mail string from the beginning of each line in a file
Find and replace inside a text file from a Bash command
Deleting multiple spaces from the beginning of each line in a file in tcl
Display integers from the file on a line
The program copies specific lines from the HTML file; Some lines break it without visible motive?
Vim: visual mode from the end of a line
Remove the empty space from the end of a line in a richtext field
How to rearrange the numbers of different lines of a text file in python?
java- How do I count spaces between paragraphs and subtract them from the total number of lines?
In Go, scan the numbers of a line using recursion
Exclude records from the first and last lines of a loop
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK