acctman
acctman

Reputation: 4349

shell cut command to remove characters

The current code below the grep & cut is outputting 51315123&category_id , I need to remove &category_id can cut be used to do that?

... | tr '?' '\n' | grep "^recipient_dvd_id=" | cut -d '=' -f 2 >> dvdIDs.txt

Upvotes: 5

Views: 17166

Answers (2)

brightlancer
brightlancer

Reputation: 2109

If you're open to using AWK:

... | tr '?' '\n' | awk -F'[=&]' '/^recipient_dvd_id=/ {print $2}' >> dvdIDs.txt

AWK handles the regex and splitting fields, in this case using both '=' and '&' as field separators and printing the second column. Otherwise, you will need a second cut statement.

Upvotes: 2

Owen
Owen

Reputation: 39356

Yes, I would think so

... | cut -d '&' -f 1

Upvotes: 11

Related Questions