Unix Blog

Monday, October 25, 2010

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

posted by Jayanthi Krishnamurthy @ 10:49 AM   0 Comments

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

Newer›  ‹Older

About Me

Name: Jayanthi Krishnamurthy

View my complete profile

Posts

  • cut example

Older Posts Newer Posts

Archives

Subscribe to
Posts [Atom]