Operating System - HP-UX
1837893 Members
3054 Online
110122 Solutions
New Discussion

Re: some grepping and seding

 
Amit Dixit_2
Regular Advisor

some grepping and seding

Hi
I have a directory list like this
CD_1.0
REL_3.0

I want a command through which I can just
extract the numerical part if i replace
SUFFIX BEFORE "_"

Thanks
Amit
8 REPLIES 8
RAC_1
Honored Contributor

Re: some grepping and seding

Is numerical part always after _ ??

awk -F "_" '{print $2}'

Anil
There is no substitute to HARDWORK
Bharat Katkar
Honored Contributor

Re: some grepping and seding

Hi Amit,
Is what you are looking for:
# pwd
/abc
# ll
total 0
drwxrwxrwx 2 root sys 96 Aug 9 17:50 CD_1.0
drwxrwxrwx 2 root sys 96 Aug 9 17:52 REL_3.0
# ll | cut -d "_" -f2
total 0
1.0
3.0
#
Regards,


You need to know a lot to actually know how little you know
Steve Steel
Honored Contributor

Re: some grepping and seding

Hi

echo $value|cut -f2 -d"_"


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Amit Dixit_2
Regular Advisor

Re: some grepping and seding

Hi Bharat,

How to get rid of total and and how to
assign this value to a variable.

Thanks
Amit
Massimo Bianchi
Honored Contributor

Re: some grepping and seding

Hi,
what about:

VALUE=$( ls | cut -d "_" -f2 )

echo $VALUE


HTH,
Massimo
Kent Ostby
Honored Contributor

Re: some grepping and seding

As Massimo points out, you can assign a value for any of these commands as:

VALUE=$()

To clarify the awk command that someone listed above, you'd need:

ll | awk -F "_" '{print $2}'

or

VALUE=$( ll | awk -F "_" '{print $2}')

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Bharat Katkar
Honored Contributor

Re: some grepping and seding

Amit,
See if this works for you.

#!/usr/bin/ksh
list=`ls | cut -d "_" -f 2`
funct1 $list
funct1()
{
V1=$#
x=1
while true
do
if [ $V1 -gt 0 ]
then
VAR$x=$1
shift
let x=x+1
let V1=V1-1
else
exit
fi
done
}

Hope that helps.
Regards,
You need to know a lot to actually know how little you know
Muthukumar_5
Honored Contributor

Re: some grepping and seding

We can do it with awk programming easily as,

# ls
CD_1.0 REL_3.0 test_4.0
# ls | awk -F _ '{ s += $2 } END { print "sum = " s }'
sum = 8


It will give the value. You can assign to a new variable and can be used in operation following this.

And one more ,

your profile says as,
http://forums1.itrc.hp.com/service/forums/publicProfile.do?userId=CA1059455&forumId=1

I have assigned points to 78 of 400 responses to my questions.

It is good to take time to resolve this :)

Easy to suggest when don't know about the problem!