Solved

Perl pos and Solaris cut.

Posted on 2003-10-24
2
967 Views
Last Modified: 2013-12-05
I'm having trouble finding the equivilant of solaris cut in perl

I need to cut a string such as HSTNTXTXCA and grab the state character possition 5 and 6..

solaris equiv:

TID='HSTNTXBGFOMA'
STATE=`echo $TID|cut -c5-6`
0
Comment
Question by:Satalink
2 Comments
 
LVL 2

Accepted Solution

by:
ultimatemike earned 100 total points
ID: 9614444

Use substr.  it will return the specifified string that you're looking for.


use strict;

my $TID='HSTNTXBGFOMA';
my $state= substr($TID,  4, 2 );
0
 
LVL 12

Expert Comment

by:geotiger
ID: 9616824
Or use pattern match as this:

my $tt = "ddff33yy";
my ($s) = ($tt =~ /^\w\w\w\w(\w\w)/);
print "S=$s\n";


GT
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

837 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