1 liner question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 1 liner question
# 1  
Old 03-09-2009
1 liner question

This works:

nslookup `uname -n`|tail -2|awk -F: '{print $2}'

This does not

aa=`nslookup `uname -n`|tail -2|awk -F: '{print $2}'`


Why???

Solaris v10

Thanks
Brandt
# 2  
Old 03-09-2009
Some shells have a problem with backtics inside backtics use : $( ) instead.
# 3  
Old 03-09-2009
Because you need to escape the inner backticks:

Code:
aa=`nslookup \`uname -n\`|tail -2|awk -F: '{print $2}'`

I believe there is a better way to extract the above information though ...
# 4  
Old 03-09-2009
What would be the better way? Please & Thanks!!
# 5  
Old 03-09-2009
Radoulov,

Your backticks worked well, I will use that!!

Thanks All!!
# 6  
Old 03-09-2009
If your shell supportsthe $() syntax for process substitution:
Code:
addr="$(perl -MSocket -e'
  print inet_ntoa(~~gethostbyname$ENV{"HOSTNAME"})
  ')"

Or:

Code:
addr="$(nslookup "$HOSTNAME"|nawk '/^Add/&&c++{print $NF}')"


Or:

Code:
addr="$(getent hosts "$HOSTNAME"|cut -f1)"


Last edited by radoulov; 03-09-2009 at 01:14 PM..
# 7  
Old 03-09-2009
All works!!

Again Thanks!!

Brandt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell one liner help

Hello, I am trying to sort/get some specific output from a ls command but however I am having no luck. The command I am using is 'ls -al /nim/dr/mksysb/\*'|grep -e _dr -e .tgz|cut -c37-90|cut -d" " -f2-8|cut -d_ -f1 the error is bash: ls -al /nim/dr/mksysb/\*: No such file or directory ... (1 Reply)
Discussion started by: hasn318
1 Replies

2. Shell Programming and Scripting

PERL one liner

hi, I am using PERL one liner for oracle database connection as : $PERL -e "use DBI; DBI->connect(qw(DBI:Oracle:SID user passwd));" is there a way to append select statement to this connection ? i.e. DB connection and select stmt in one line ? how to do sysdba connection using one lines... (1 Reply)
Discussion started by: talashil
1 Replies

3. Shell Programming and Scripting

awk one liner

The below code is a simple modified sample from a file with millions of lines containing hundreds of extra columns xxx="yyy" ... <app addr="1.2.3.4" rem="1000" type="aaa" srv="server1" usr="user1"/> <app usr="user2" srv="server2" rem="1001" type="aab" addr="1.2.3.5"/>What's the most efficient awk... (2 Replies)
Discussion started by: cabrao
2 Replies

4. Shell Programming and Scripting

help with sed one liner

hey everyone, I want to remove some characters from a string that i have with sed. For example if my string is: a0=bus a1=car a2=truck I want my output to look like this: bus car truck So i want to delete the two characters before the = and including the =. This is what i came up with... (3 Replies)
Discussion started by: GmGeubt
3 Replies

5. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

6. Shell Programming and Scripting

Awk one-liner?

Hello, I have two files... File #1 1 3 2 5 File #2 3 5 3 1 3 7 9 1 5 2 5 8 3 3 1 I need to extract all lines from File #2 where the first two columns match each line of File #1. So in the example, the output would be: 1 3 7 2 5 8 Is there a quick one-liner that would... (4 Replies)
Discussion started by: palex
4 Replies

7. Shell Programming and Scripting

help one liner...

Hi I have a log data that shows chunks of data like this: thisis example test, this is example test, this is example test thisis example test, this is example test, this is example test thisis example test, this is example test, this is example test thisis example test, this is example test,... (2 Replies)
Discussion started by: erick_tuk
2 Replies

8. Shell Programming and Scripting

Need a one liner

abc/abc1/abc2/abc3/abc4 i need a script to pick this above path when ever any patterns like the below will be found. abc/abc1 abc/abc1/abc2 abc1/abc2/abc3 abc2/abc3/abc4 abc2/abc3/ etc .... etc..... not only the above 5 but like these one.. any one liner will be of great... (1 Reply)
Discussion started by: debu182
1 Replies

9. Shell Programming and Scripting

awk one liner

input a 100 200 300 b 400 10 output a 100 a 200 a 300 b 400 b 10 Thanx (6 Replies)
Discussion started by: repinementer
6 Replies

10. Shell Programming and Scripting

Perl One Liner

Hi , Can anybody explain how this perl one liner works.. It is to test whether the number is prime or not perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19 Thanks in advance Shihab (2 Replies)
Discussion started by: shihabvk
2 Replies
Login or Register to Ask a Question