Sed: Difference between revisions
Jump to navigation
Jump to search
Anthoanthop (talk | contribs) No edit summary |
Anthoanthop (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
= Print a pattern between two (exclusive) words ) | |||
echo "pattern" | sed -e 's/.*WORD1//' -e 's/WORD2.*$//' | echo "pattern" | sed -e 's/.*WORD1//' -e 's/WORD2.*$//' | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 19: | Line 16: | ||
ns612429.ip-45-102-38.eu | ns612429.ip-45-102-38.eu | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= Replace new lines with a comma and a space = | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sed -z 's/\n/, /'g my_file | sed -z 's/\n/, /'g my_file | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 15:08, 29 November 2015
= Print a pattern between two (exclusive) words )
echo "pattern" | sed -e 's/.*WORD1//' -e 's/WORD2.*$//' </syntaxhighlight>
Example:
$ ./ovh-api-bash-client.sh --url "/ip/45.102.38.141"
200 {"organisationId":null,"country":"fr","routedTo":{"serviceName":"ns612429.ip-45-102-38.eu"},"ip":"45.102.38.141/32","canBeTerminated":true,"type":"failover","description":null}
If we only want the routedTo information:
$ ./ovh-api-bash-client.sh --url "/ip/45.102.38.141" | sed -e 's/.*serviceName":"//' -e 's/"},"ip":.*$//'
ns612429.ip-45-102-38.eu
Replace new lines with a comma and a space
sed -z 's/\n/, /'g my_file