Sponsored Content
Top Forums Shell Programming and Scripting How to print last character of hostname and assign to a variable ? Post 303034006 by MadeInGermany on Tuesday 16th of April 2019 11:05:52 AM
Old 04-16-2019
Most if not all awk versions have length() default to $0.
So you can say length() and even length.
Likewise, in substr() the 3rd parameter defaults to "unlimited", so can be omitted here, because there is only 1 character left.
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

read and assign each character from the string to a variable

How... can I read input by a user character by cahracter. And assign each character from the string to a variable? Any help would be greatly appreciated! Thank you! (1 Reply)
Discussion started by: Tek-E
1 Replies

2. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: yxian
7 Replies

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

4. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

5. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

6. Programming

Unable to assign zero to unsigned character array

Hi, I am unable to assign value zero to my variable which is defined as unsigned char. typedef struct ABCD { unsigned char abc; unsigned char def; unsigned char ghi; } ABCD; typedef ABCD *PABCD; In my Por*C code, i assign the values using memcpy like below ... (3 Replies)
Discussion started by: gthangav
3 Replies

7. Shell Programming and Scripting

Assign a variable the nth character of a string.

I see a millioin ways to do this with echo, but what I wan to do is assign a variable the "nth" character of an incoming parameter to a ksh script. $1 will be "pia" I need to assign the first character to stmttype. (10 Replies)
Discussion started by: klarue
10 Replies

8. Shell Programming and Scripting

Remove a character and assign result to a variable

I am reading lines from a file that contain a number sign (#) before a three or four digit number: #1043 #677 I can remove the '#' and get just the number. However, I then want to assign that number to a variable and use it as part of a path further on in my program: /mydir/10/1043 for... (5 Replies)
Discussion started by: KathyB148
5 Replies

9. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
POE::Filter::Block(3pm) 				User Contributed Perl Documentation				   POE::Filter::Block(3pm)

NAME
POE::Filter::Block - translate data between streams and blocks SYNOPSIS
#!perl use warnings; use strict; use POE::Filter::Block; my $filter = POE::Filter::Block->new( BlockSize => 8 ); # Prints three lines: abcdefgh, ijklmnop, qrstuvwx. # Bytes "y" and "z" remain in the buffer and await completion of the # next 8-byte block. $filter->get_one_start([ "abcdefghijklmnopqrstuvwxyz" ]); while(1) { my $block = $filter->get_one(); last unless @$block; print $block->[0], " "; } # Print one line: yz123456 $filter->get_one_start([ "123456" ]); while(1) { my $block = $filter->get_one(); last unless @$block; print $block->[0], " "; } DESCRIPTION
POE::Filter::Block translates data between serial streams and blocks. It can handle fixed-length and length-prepended blocks, and it may be extended to handle other block types. Fixed-length blocks are used when Block's constructor is called with a BlockSize value. Otherwise the Block filter uses length-prepended blocks. Users who specify block sizes less than one deserve what they get. In variable-length mode, a LengthCodec parameter may be specified. The LengthCodec value should be a reference to a list of two functions: the length encoder, and the length decoder: LengthCodec => [ &encoder, &decoder ] The encoder takes a reference to a buffer and prepends the buffer's length to it. The default encoder prepends the ASCII representation of the buffer's length and a chr(0) byte to separate the length from the actual data: sub _default_encoder { my $stuff = shift; substr($$stuff, 0, 0) = length($$stuff) . ""; return; } The corresponding decoder returns the block length after removing it and the separator from the buffer. It returns nothing if no length can be determined. sub _default_decoder { my $stuff = shift; unless ($$stuff =~ s/^(d+)//s) { warn length($1), " strange bytes removed from stream" if $$stuff =~ s/^(D+)//s; return; } return $1; } This filter holds onto incomplete blocks until they are completed. PUBLIC FILTER METHODS
POE::Filter::Block has no additional public methods. SEE ALSO
Please see POE::Filter for documentation regarding the base interface. The SEE ALSO section in POE contains a table of contents covering the entire POE distribution. BUGS
The put() method doesn't verify block sizes. AUTHORS &; COPYRIGHTS The Block filter was contributed by Dieter Pearcey, with changes by Rocco Caputo. Please see POE for more information about authors and contributors. perl v5.14.2 2012-05-15 POE::Filter::Block(3pm)
All times are GMT -4. The time now is 12:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy