LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2008, 06:18 AM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Korn Shell & Printing Certain Output


I have this output using Korn Shell. The output that I like is fine.

PHP Code:
                        Ping    Telnet  Logable?
NAM                     Status  (Nmap)  (Expect)
=================================================
192.119.12.2            up      open     No  
192.119.12.3            up      open     No  
192.119.12.4            up      open     No  
192.119.12.5            up      open     No  
192.119.12.6            down    No       No  
192.119.12.7            up      open     No  
192.119.12.8            up      open     No 
but if I wanted to add an additional column and have it print out a version like:

PHP Code:
                        Ping    Telnet  Logable?
NAM            Version  Status  (Nmap)  (Expect)
=================================================
192.119.12.2   2.1      up      open     No  
192.119.12.3   2.1      up      open     No  
192.119.12.4   3.5      up      open     No  
192.119.12.5   3.5      up      open     No  
192.119.12.6   3.5      down    No       No  
192.119.12.7   3.6      up      open     No  
192.119.12.8   3.6      up      open     No 
So instead of having to do this several times:

PHP Code:
printf "                         Ping    Telnet  Logable?\n" 
printf "NAM            Version   Status  (Nmap)  (Expect)\n"
printf "=================================================\n"
printf "                2.1                              \n"
printf "                2.1                              \n"
printf "                3.5                              \n"
printf "                3.5                              \n"
printf "                3.5                              \n"
printf "                3.6                              \n"
printf "                3.6                              \n" 
How can I print this more efficiently? Can I simply make a constant and then say print this constant several times. Bare with me for I am a novice at programming.

Last edited by metallica1973; 01-10-2008 at 07:07 AM.
 
Old 01-10-2008, 08:14 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
maybe like this (using TABs to format)


Code:
#!/bin/ksh

name=thingy
version=99.9


cat <<EOF
                          Ping    Telnet  Logable?
 NAM    Version   Status  (Nmap)  (Expect)
 =================================================
        2.1
        2.1
        3.5
$name   $version
EOF
Code:
$ ./1.sh
                          Ping    Telnet  Logable? 
 NAM    Version   Status  (Nmap)  (Expect)
 =================================================
        2.1                              
        2.1                              
        3.5                              
thingy  99.9
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Globbing using Korn Shell metallica1973 Programming 1 12-05-2007 04:56 PM
script in korn shell disruptive Programming 15 02-22-2007 10:18 AM
KORN: Looping through output of command eur0dad Programming 4 08-03-2006 02:57 PM
Korn Shell PS1 c19h28O2 Linux - Newbie 4 04-25-2006 06:56 AM
a t&t korn shell 93 shook Linux - Software 4 02-01-2003 01:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration