Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell cut command to remove characters

Tags:

bash

shell

cut

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
like image 390
acctman Avatar asked Dec 22 '22 10:12

acctman


2 Answers

Yes, I would think so

... | cut -d '&' -f 1
like image 146
Owen Avatar answered Feb 07 '23 00:02

Owen


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.

like image 39
brightlancer Avatar answered Feb 07 '23 00:02

brightlancer