Help me with simple shell script.

Hello forum members,

I have to redirect a output of command into a text file inside a script file but iam getting an errors.so please see below script and suggest me for corrections.

#!/bin/ksh
read IP_ADD
echo nslookup $IP_ADD  2>&1| tee log1.txt
cat  /amex/gcst/siva/Testr/log1.txt
awk '/^Name:/{print $2} ' log1.txt

output of nslookup command.

 
Server:  PHXIPCQIPAPPL05.ipc.us.aexp.com
Address:  193.201.110.119
Name:    spdma505.gcg.ikl.us.ecil.com
Address:  144.156.254.15

the above output have redirect nslookup into into log1.txt.
i am trying to print the name.:b:

Thanks & Regards
Rajkumar g

why do you want to use "echo" ? try remove this and try again

#!/bin/ksh
read IP_ADD
echo nslookup $IP_ADD  2>&1| tee log1.txt
cat  /amex/gcst/siva/Testr/log1.txt
awk '/^Name:/{print $2} ' log1.txt
1 Like

I want to print only name in the below stuff.

Server:  PHXIPCQIPAPPL05.ipc.us.aexp.com
Address:  193.201.110.119
Name:    spdma505.gcg.ikl.us.ecil.com
Address:  144.156.254.15

i want only name it displaying again complete file after writing like this also

# !/bin/ksh
read IP_ADD
nslookup $IP_ADD  2>&1| tee log1.txt
#cat  /amex/gcst/siva/Testr/log1.txt
awk '/^Name:/{print $2} ' log1.txt

can you please correct it.:b:

thanks again

Just include -F: in the awk statement..

awk -F: '/^Name:/{print $2} ' log1.txt
#Output
            spdma505.gcg.ikl.us.ecil.com

To remove those leading spaces..try..

awk -F: '/^Name:/ {print $2}'| tr -d " " < log1.txt
#Output:
spdma505.gcg.ikl.us.ecil.com

again it was giving output like below. but i want only Name.

tpfa.ipc.hy.ecil.com

but it printing below code also.

Server:  PHXIPCQIPAPPL05.ipc.us.aexp.com
Address:  168.131.110.2
Name:    tpfa.ipc.us.aexp.com
Address:  168.131.96.1

if run it need print tpfa.ipc.hy.ecil.com

thanks for reply.:b:

It wud be fine posting your desired output..

If all that you want to do is extract the "Name" field, we don't need workfiles.

#!/bin/ksh
read IP_ADD
nslookup "${IP_ADD}"  2>&1 | awk '/^Name:/{print $2} '