Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing data in Bash

Tags:

bash

parsing

I have a file with lots of Rubbish inside. All of it is in one line. But there are often things like:

"var":"value" 

Before and after are different characters ...

What I want to do is, to extract only the above mentioned format and put them into a single line. Any ideas how I could realize it in Shell scripting?

Best regards, Alex

like image 207
Alex Ander Avatar asked Jul 17 '26 22:07

Alex Ander


1 Answers

I believe

grep -o '"[^"]*":"[^"]*"' yourFile.txt > yourOutput.txt

would do the trick:

> echo 'xxx "a":"b" yyy"x":"y"' | grep -o '"[^"]*":"[^"]*"'
"a":"b"
"x":"y"
like image 192
Rody Oldenhuis Avatar answered Jul 20 '26 15:07

Rody Oldenhuis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!