Solved

Perl pos and Solaris cut.

Posted on 2003-10-24
2
963 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

832 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