The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To call/execute a shell script from a shell script konark UNIX for Dummies Questions & Answers 1 10-26-2007 02:16 PM
How to pass a parameter from one Shell-script to another Shell-script subodhbansal Shell Programming and Scripting 2 09-22-2007 02:19 AM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 05:42 PM
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 1 04-30-2007 05:43 AM
Have a shell script call another shell script and exit heprox Shell Programming and Scripting 2 11-20-2006 04:17 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-28-2005
Registered User
 

Join Date: Aug 2005
Posts: 7
Shell Script Help

Hi All,
I have a input file:

hostnames.txt
ssh,server1,user
ssh,server2,user
ssh,server3,user
ssh,server4,user

So can someone guide me as how to read this file and display the output as follow using a ksh.

server1 server2 server3 server4

Thanks,
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-28-2005
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,323
It is quite easy if you fiddle with the IFS.
Code:
#!/bin/ksh
oldIFS=IFS
IFS=$IFS","
while read junk1 server junk2; do
echo "$server \c"
done < hostname.txt
IFS=$oldIFS
Reply With Quote
  #3 (permalink)  
Old 10-29-2005
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,502
or even easier in awk.

Code:
awk -F\, '{printf "%s ", $2}' hostname.txt
Reply With Quote
  #4 (permalink)  
Old 10-29-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Code:
#!/bin/ksh
while IFS=',' read junk1 server junk2; do
    echo "$server \c"
done < hostname.txt
Reply With Quote
  #5 (permalink)  
Old 10-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 7
Thanks to vgersh99, reborg, blowtorch that is exactly what I was trying to do. Now to continue with this..what I am trying to do is create an html link for each servername which will look like this in a txt file:

<a href="#server1">server1</a> <a href="#server2">server2</a> <a href="#server3">server3</a>

and so on:


I tried the following however it doesn't seem to be working. The output comes out to be one link instead of individual links. Can you guys provided some assistance with this. Thank you. Here is what I tried doing:
hostFile = hostnames.txt
hostlinks = `awk -F\, '{printf "%s ", $2}' $hostFile`
printf "<a href=#$hostlinks>$hostlinks</a>"

Obviously with this hostlinks output becomes one big link.
Reply With Quote
  #6 (permalink)  
Old 10-31-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Code:
hostFile = hostnames.txt
nawk -F, '{printf("<a href=#$hostlinks>%s</a>\n", $2)}' $hostFile
Reply With Quote
  #7 (permalink)  
Old 10-31-2005
Registered User
 

Join Date: Aug 2005
Posts: 7
Hey versh99 thanks for the response. With this code from you I am almost there:

hostFile = hostnames.txt
nawk -F, '{printf("<a href=#$hostlinks>%s</a>\n", $2)}' $hostFile

however the above code is giving this link:

http://singhb.hiw.com/hostusers/hostuserhtml.html#$hostlinks

Can the $hostlinks variable be replace where it will show the actual server name.

I tried replacing the $hostlinks with $2 however that only chnaged the html to:

http://singhb.hiw.com/hostusers/hostuserhtml.html#$2

Thanks for your assistance with this.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0