Alex Ander
Alex Ander

Reputation: 31

Parsing data in Bash

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

Upvotes: 3

Views: 1140

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38052

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"

Upvotes: 4

Related Questions