chrisvo
asked on
awk substring question
How do I use the substring function in awk?
I am trying to do this on a Solaris box;
for example given string 123456789... (unknown length)
I would like to get back the substring which excludes the first n characters ie for first 3 characters return 456789...
I am trying to do this on a Solaris box;
for example given string 123456789... (unknown length)
I would like to get back the substring which excludes the first n characters ie for first 3 characters return 456789...
ASKER
Yes, but how do you assign the result to another variable?
For example,
if $NUM is an argument passed to a script,
could this be done:
$short=`echo $NUM | awk '{print substr($NUM,4}'`
I think I'm doing something wrong because the script fails
to output the value of $short
For example,
if $NUM is an argument passed to a script,
could this be done:
$short=`echo $NUM | awk '{print substr($NUM,4}'`
I think I'm doing something wrong because the script fails
to output the value of $short
Hi...
Checkout your $ symbol when you assigned your variable with command sunstitution...
$var="will get you every time"
better...
var="ok you assigned me"
echo $var
regards
Checkout your $ symbol when you assigned your variable with command sunstitution...
$var="will get you every time"
better...
var="ok you assigned me"
echo $var
regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
substr(str1, 4),
for unknown length, example
echo 1234567890 | awk {'print substr($0, 4)'}