Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract part of text using bash on a large file

I have huge log file where I want to extract part of the log which looks like this:
—-TEXT NOT NEEDED— yValues:10 zValues:1254 —-TEXT NOT NEEDED—
—-TEXT NOT NEEDED— yValues:10 zValues:1254 —-TEXT NOT NEEDED—
—-TEXT NOT NEEDED— yValues:10 zValues:1254 —-TEXT NOT NEEDED—
….
This is a huge file and this yValues and zValues are repeated throughout.
Opening the file is very slow, so I am trying to extract this part of the text only.
If I do grep yValues, it still gives the whole line and so file saved is still a large file.
How can this be done using bash?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

grep has a -o/--only-matching option to do what you want:

$ grep --only-matching 'yValues:[0-9]\+' <<EOF
----TEXT NOT NEEDED--- yValues:10 zValues:1254 ----TEXT NOT NEEDED---
----TEXT NOT NEEDED--- yValues:10 zValues:1254 ----TEXT NOT NEEDED---
----TEXT NOT NEEDED--- yValues:10 zValues:1254 ----TEXT NOT NEEDED---
EOF
yValues:10
yValues:10
yValues:10
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading