Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut Utility help.

Status
Not open for further replies.

ranjank

IS-IT--Management
May 9, 2003
176
IN
Hi All,

I have got one file which contains variables defined and the PATHS assigned to the respective variables.For e.g

file abc
PROS=x86; export PROS
CONT=/usr/local/ver/1.00; export CONT
PRO=PRS; export PRO

I want to extract the path till /us/local/ver in CONT variable.IS it possible to do with cut utility or is there any other way by which i can do it.Any help on this will be greatly appreciated.

Regards,
RK.
 
Thanks.I tried with this option but it is giving the output for all the three variables.Or i'm doing it in the wrong way.

Rgds,
RK.
 
man awk

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV

I need to extract only /usr/local/ver with awk.Can you tell me with example.

Rgds,
RK
 
For the cut example, adjust the characters returned by adjusting 1-24 appropriately. To get only that line, grep for CONT before using the cut.
 
awk 'BEGIN{FS="[=;]"}$1=="CONT"{print $2}' abc

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks a lot PHV.I tried it but it is giving me the whole out out like /usr/local/ver/1.00.How can i extract only /usr/local/ver leaving 1.00.

Rgds,
RK.
 
Try nawk instead of awk.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV

nawk is not installed in my unix machine.As i'm newbie to shell scripting can u suggest any other way thru which i can achieve my objective.Help on this will be highly appreciated.

Rgds,
RK.

 
awk '/CONT=/{x=$0;sub(".*CONT=","",x);sub(";.*","",x);print x}' abc

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV

I'm getting the same out put /usr/local/ver/1.00.

Rgds,
RK.
 
Sorry, misread the leaving part:
awk '/CONT=/{x=$0;sub(".*CONT=","",x);sub("/[^/]*","",x);print x}' abc

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I got it.....Thanks a lot to PHV and Futurelet.Also thanks to kencunningham.
This one worked for me.

awk 'BEGIN{FS="=|/[^/]*$"}/^CONT/ {print $2}' abc

Again thanks a lot to every one who contributed to my question.

Rgds,
RK.
 
This might only work on your sample file, but I get the desired results with:

$more file1
PROS=x86; export PROS
CONT=/usr/local/ver/1.00; export CONT
PRO=PRS;exportPRO
$
$ ./doit3 file1
/usr/local/ver
$
$ cat doit3
dirname `cat $1|grep CONT|awk -F = '{ print $2 '}|awk -F ";" '{ print $1 '}`
 
This might only work on your sample file, but I get the desired results with:
Code:
dirname `cat file1|grep CONT|awk -F = '{ print $2 '}|awk -F ";" '{ print $1 '}`

$cat file1
PROS=x86; export PROS
CONT=/usr/local/ver/1.00; export CONT
PRO=PRS;exportPRO
$

 
Ya ur right motoslide....I tried ur option also its working fine.thanks a lot.

Rgds,
RK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top