Solved

Script Needed Urgent

Posted on 2011-03-06
5
385 Views
Last Modified: 2012-05-11
simple script in a scripting language  that prints the numbers from 1 to 100. But for multiples of three print "Site" instead of the number and for the multiples of five print "Host". For numbers which are multiples of both three and five print "SiteHost".
0
Comment
Question by:Reddy4U-Solaris
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
Comment Utility
for ($n=1; $n <= 100; $n++)
{
    if ( ( $n % 15 ) == 0 ) { print "SiteHost\n"; }
    elsif (( $n % 3 ) == 0 )  { print "Site\n"; }
    elsif (( $n % 5 ) == 0 )  { print "Host\n"; }
    else { print "$n\n"; }
}

Open in new window



c:\temp>perl foo.pl
1
2
Site
4
Host
Site
7
8
Site
Host
11
Site
13
14
SiteHost
16
17
Site
19
Host
Site
22
23
Site
Host
26
Site
28
29
SiteHost
31
32
Site
34
Host
Site
37
38
Site
Host
41
Site
43
44
SiteHost
46
47
Site
49
Host
Site
52
53
Site
Host
56
Site
58
59
SiteHost
61
62
Site
64
Host
Site
67
68
Site
Host
71
Site
73
74
SiteHost
76
77
Site
79
Host
Site
82
83
Site
Host
86
Site
88
89
SiteHost
91
92
Site
94
Host
Site
97
98
Site
Host

Open in new window

0
 

Author Comment

by:Reddy4U-Solaris
Comment Utility
thanks thats usefull can u tell me which scripting u r using
0
 

Author Closing Comment

by:Reddy4U-Solaris
Comment Utility
Excellent Response
0
 
LVL 16

Expert Comment

by:sjklein42
Comment Utility
That's PERL.

Thanks.
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
bash version is virtually the same

#!/bin/bash
for i in $(seq 1 100)
do
  if [ $(($i%15)) -eq 0 ]
  then
     echo SiteHost
  elif [ $(($i%3)) -eq 0 ]
  then
     echo Site
  elif [ $(($i%5)) -eq 0 ]
  then
     echo Host
  else
     echo $i
  fi

don

Open in new window

e
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now