[ art / civ / cult / cyb / diy / drg / feels / layer / lit / λ / q / r / sci / sec / tech / w / zzz ] archive provided by lainchan.jp

lainchan archive - /tech/ - 34940

File: 1487955365432.png (103.19 KB, 300x300, R-9812109.jpg)


What's the recommended linux command for filtering piped output ? If I have a command that outputs something like:

gym_las 9/200

Can I pipe this into something so the output is just 9 ?
should I look intro grep and regex ?


Grep is good enough with with ERE and only-matching options:
$ echo -e 'ofi\ngym_las 9/200\nolm' | grep -oE '9'


Sorry, I forgot to mention, the text changes all the time, and I just want x from x/y no matter what line it is.


You will want to look into sed, or sed combined with grep. Also depending on the formatting awk may come in handy.

For future reference this probably should have been asked in the technical talk thread.


Let's see if I can do this from my phone...

<Some command> | sed -e "/\d\+\/\d\+/ s/\(\d\+\)\/\d\+/\1/"

Something like that...