The UNIX and Linux Forums  
Hello and Welcome from to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to attach a file in a email ting123 UNIX for Dummies Questions & Answers 3 04-11-2009 07:03 PM
hi.. how to attach a tar file using shell script madhumathikv Shell Programming and Scripting 1 10-17-2007 07:46 AM
Howto Attach File with Sendmail monkfan UNIX for Dummies Questions & Answers 2 05-18-2006 09:43 AM
How to attach an excel file/ dat file thru unix mails diwakar82 Shell Programming and Scripting 1 01-06-2006 11:23 AM
How to attach a file in mail? firebirdonfire UNIX for Dummies Questions & Answers 1 03-29-2001 08:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-31-2008
lo tan lo tan is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
how to assign the value from the 2nd file to the 1st file, line by line..

Hi all,
I am a newbie in unix shell script world. Say, I have a list of devices in file01 and then also have file02 with the list of the location. I need to telnet to each devices in file01 and set the location according to file02. Example:
#cat file01
ttnpx01
ttnpx02
nncrd01
nncrd02
nkcrs01

#cat file02
liverpool
newtown
stockland
greenfield
newyork

With the for loop I can telnet to each device from file01, but I am not sure how to retrieve the variable from file02 and then attach to device. This is my basic script
#cat myscript
for host in `cat file01`
do
telnet $host
set location ...
done

Below is the result that I try to achieve:
ttnpx01 --> will have the location set to liverpool
ttnpx02 --> will have the location set to newtown
nncrd01 --> will have the location set to stockland
nncrd02 --> will have the location set to greenfield
nkcrs01 --> will have the location set to newyork

Can you please help? Thanks

Last edited by lo tan; 05-31-2008 at 09:22 AM..
  #2 (permalink)  
Old 05-31-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,307
One way:

Code:
awk 'NR==FNR{a[NR]=$0;next}{print a[FNR], $0}' file01 file02 |
while read host location
do
   echo $host 
   echo $location
   # do other stuff here
done
Regards
  #3 (permalink)  
Old 05-31-2008
lo tan lo tan is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
wow, thank you for your prompt respond. Your code looks good, I will check it then let you know the result. Again, thank you.
  #4 (permalink)  
Old 06-01-2008
lo tan lo tan is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
Quote:
Originally Posted by Franklin52 View Post
One way:

Code:
awk 'NR==FNR{a[NR]=$0;next}{print a[FNR], $0}' file01 file02 |
while read host location
do
   echo $host 
   echo $location
   # do other stuff here
done
Regards
Hi Franklin52,
I have tried your code, it works fine with a linux machine. However, when I tried it with a SunOS, it failed due to the awk could not combine 2 files side by side. As a newbie I am still in learning process and have not much experiences with the awk, would you able to lend me a hand please?
Below is the result from the awk and I think it is not what you meant. Thanks
#awk 'NR==FNR{a[NR]=$0;next}{print a[FNR], $0}' file01 file02
ttnpx01
ttnpx02
nncrd01
nncrd02
nkcrs01
liverpool
newtown
stockland
greenfield
newyork
  #5 (permalink)  
Old 06-02-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,307
Quote:
Originally Posted by lo tan View Post
Hi Franklin52,
I have tried your code, it works fine with a linux machine. However, when I tried it with a SunOS, it failed due to the awk could not combine 2 files side by side. As a newbie I am still in learning process and have not much experiences with the awk, would you able to lend me a hand please?
Below is the result from the awk and I think it is not what you meant. Thanks
#awk 'NR==FNR{a[NR]=$0;next}{print a[FNR], $0}' file01 file02
ttnpx01
ttnpx02
nncrd01
nncrd02
nkcrs01
liverpool
newtown
stockland
greenfield
newyork
Try it with nawk.

Regards
  #6 (permalink)  
Old 06-03-2008
lo tan lo tan is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
Quote:
Originally Posted by Franklin52 View Post
Try it with nawk.

Regards
Yes, it works with nawk. Thanks
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0