Reputation: 1444
I am trying to extract the value of a parameter from the text file.
Below is my text file with uri_param as parameter.
application.txt
---------------
uri_param=frontier://tenant=stripe;env=qa;[email protected]:80
command:
--------
egrep ^uri_param application.txt | sed -e 's/.*=//'
I am expecting the strign after first =
as output i.e. frontier://tenant=stripe;env=qa;[email protected]:80
, but the output I am getting is [email protected]:80
.
How can I fix this? What I found till now is .* in sed is greedy and it will match the longest string after =
.
Upvotes: 1
Views: 3698
Reputation: 10039
sed -n '/^uri_param=/ {s///p;q;}' YourFile
Upvotes: 3
Reputation: 14955
We can filter it in the grep
part:
grep -o "^uri_param=.*:[0-9]\{1,\}" infile|sed -e "s/^uri_param=//"
Or use a more flexible tool like gawk
:
gawk 'match($0, "^uri_param=(.*:[0-9]+)", r){print r[1]}' infile
NOTE: If your url
doesn't finish allways with the port number the pattern
should be adjusted.
Upvotes: 1