cut example
We usually assign some value to a variable and reuse the variable. There could also be situations where we need the variable name when value is passed.
Create a file named server with the following content.
server_qa_apache=1.1.1.1
server_production_jboss=2.2.2.2
I would like to pass IP as input and obtain the variable name.
grep 1.1.1.1 servers| cut -d'_' -f2
Output: qa
grep 2.2.2.2 servers| cut -d'_' -f2
Output: production
In case, you have more than one place in a file where 1.1.1.1 is used, you can limit the grep results matching the first one.
grep 1.1.1.1 servers -m 1| cut -d'_' -f2
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home