Kyle R.
Kyle R.

Reputation: 1319

Parse version of package out of HTML with sed/awk/grep?

I have been scouring the internet for some sort of clue, but to no avail. I need a sed/awk/grep command that will parse out some text. The text is too big to post here, but if you run

curl -l "https://aur.archlinux.org/rpc.php?type=search&arg=wine"

you'll see what I mean. Basically, I need to display just the Version number of everything that returns in the search. If you could explain the sed/awk/grep syntax to me, that would be greatly appreciated.

Upvotes: 0

Views: 419

Answers (2)

Kent
Kent

Reputation: 195269

if I would extract things from text in shell, I would consider grep first.

grep -oP '(?<="[vV]ersion":")[^"]*'

this will give you all versions. (only version/Version info in output)

in your case, you may want to give it a try:

 curl -l "https://aur.archlinux.org/rpc.php?type=search&arg=wine"|grep -oP '(?<="[vV]ersion":")[^"]*'

Upvotes: 0

Andy Lester
Andy Lester

Reputation: 93805

What that is giving you back is a JSON structure. You don't parse it, you write a program to do it.

This is not something that sed, awk or grep are going to be able to do. You'd need to write a program in a language like Perl that uses the JSON Perl module. Every language has a module that will parse JSON and put it into that language's array or structure format.

Upvotes: 1

Related Questions