Sponsored Content
Top Forums Shell Programming and Scripting Print the first four characters of hostname Post 302141411 by yxian on Friday 19th of October 2007 12:14:29 AM
Old 10-19-2007
Print the first four characters of hostname

Hey,
I'm trying to print the first four characters of the hostname of a computer.

I can get it from using:
hostname -s | sed 's/...........$//'"

but this is when I know how many characters are in the computer name.

I dont understand why some like:
hostname -s | sed '/..../p'
wont work?

Any ideas?

Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

2. Shell Programming and Scripting

Print the characters in a word

Hi, How can I split the characters in a word? For Eg: If my input is: command my output should be: c o m m a n d Please help me in doing it so. (5 Replies)
Discussion started by: chella
5 Replies

3. Shell Programming and Scripting

print 10 characters in series

suppose fileA kanika123ABC 1222222222222222 raciat5678ty 1221123333331121 jessica78ulllo 2233243223333333 so output shud be print only first 10 characters in series and rest remain same kanika123A 1222222222222222 raciat5678 1221123333331121 jessica78u ... (1 Reply)
Discussion started by: cdfd123
1 Replies

4. Shell Programming and Scripting

print ip to hostname with array

Hi Anyone can help me??i writing a perl using array to translate ip address to the hostname my script are below.this line print "$myhost{$ipaddr}\n"; blank :mad:hostname dint come out:mad::mad: #!/usr/local/bin/perl @ipaddr=("192.1.168.2","172.25.1.13","129.1.2.5"); %myhost = { 192.1.168.2... (4 Replies)
Discussion started by: netxus
4 Replies

5. Shell Programming and Scripting

Use awk to print first 6 characters

Hi, i want to use awk to print the first 6 characters of a variable awk -F"|" '$3>0 { print $3 }' z00.unl > z001.unl but $3= 7 digits and i just want to print the first 6 digits. eg 1005779 but i want to print only 100577 (3 Replies)
Discussion started by: dealerso
3 Replies

6. Shell Programming and Scripting

Print N characters in ksh

Hi, I have this header on a script: echo "*************************************" How can I print 1000 "*" characters without to put them on the echo command? Understand? THIS IS AN EXAMPLE WHAT I NEED: print "1000 *" Or is possible to print or echo "*" characters until they... (8 Replies)
Discussion started by: iga3725
8 Replies

7. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

8. Shell Programming and Scripting

How to print the first 7 characters of each column

Hello all, I have a data like this: X:04252 X:05524 X:04176 X:05509 X:05524 X:04674- X:1662912 X:10181 X:16491 X:05506 X:05216- X:05488 X:46872 X:08471 X:04834 X:30170 The except result is like this: X:04252 X:05524 X:04176 X:05509 X:05524 X:04674 X:16629 X:10181... (3 Replies)
Discussion started by: yhkoo
3 Replies

9. Shell Programming and Scripting

How to print last character of hostname and assign to a variable ?

Hi How to pass echo output to a variable ? Does below awk command will get the last character of hostname and assign to a variable - "svr" ? svr=$( echo `hostname` | awk '{print substr($0,length,1)}' ) Thanks. Please use CODE tags when dsplaying code segments, sample input, and sample... (7 Replies)
Discussion started by: Lim
7 Replies

10. Shell Programming and Scripting

awk remote multiple hosts print remote hostname and output

Hi all, i'm trying to gether multiple pattern on remote hosts, and trying to print hostname and the pattern, ssh remoteserver1 -C 'hostname 2>&1;cat /var/log/server1.log | awk -F ";" '"'"'{ print " "$2" "$5}'"'"'| sort | uniq -c | sort -g -r ' The output is the following, remoteserver1 ... (8 Replies)
Discussion started by: charli1
8 Replies
GEOIP_COUNTRY_CODE3_BY_NAME(3)						 1					    GEOIP_COUNTRY_CODE3_BY_NAME(3)

geoip_country_code3_by_name - Get the three letter country code

SYNOPSIS
string geoip_country_code3_by_name (string $hostname) DESCRIPTION
The geoip_country_code3_by_name(3) function will return the three letter country code corresponding to a hostname or an IP address. PARAMETERS
o $hostname - The hostname or IP address whose location is to be looked-up. RETURN VALUES
Returns the three letter country code on success, or FALSE if the address cannot be found in the database. EXAMPLES
Example #1 A geoip_country_code3_by_name(3) example This will print where the host example.com is located. <?php $country = geoip_country_code3_by_name('www.example.com'); if ($country) { echo 'This host is located in: ' . $country; } ?> The above example will output: This host is located in: USA SEE ALSO
geoip_country_code_by_name(3), geoip_country_name_by_name(3). PHP Documentation Group GEOIP_COUNTRY_CODE3_BY_NAME(3)
All times are GMT -4. The time now is 02:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy