Ian Jaylo Guinto
Ian Jaylo Guinto

Reputation: 41

How can I remove specific character in the output of my curl

curl http://localhost:8080/api/examples-services/postcode/Sydney | json_pp | grep -E '"' | cut -d \  -f7,8,9,10 | tr -d '",:,'

My output

What I'd want to do is to remove the numbers and the NSW in that output. And also if there's a proper way to do that, I don't think my code is the proper way to do it.

Upvotes: 0

Views: 1696

Answers (1)

Ronan Boiteau
Ronan Boiteau

Reputation: 10138

You can use sed's substitute command (s).

Piping your output to this command will get read of all your NSW:

sed 's/NSW//'

sed's substitute command works like this: s/regexp/replacement/flags. So here, on each line, we are replacing NSW by nothing (without any flag).

Also, if you have multiple NSW per line that you want to remove, you can use the g (global) flag:

sed 's/NSW//g'

More information about sed's substitute command.

Upvotes: 3

Related Questions