System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

need a particular word from the file in Korn shell scripting

 
SOLVED
Go to solution
jenith christopher
Occasional Advisor

need a particular word from the file in Korn shell scripting

Hi all,

I have the file called /tmp/lvt

i need those words starts with " and ends with "

output of the file is,

Warning: rounding up logical volume size to extent boundary at size "64" MB.
Logical volume "/dev/vg00/lvol9" has been successfully created with
character device "/dev/vg00/rlvol9".
Logical volume "/dev/vg00/lvol9" has been successfully extended.
Volume Group configuration for /dev/vg00 has been saved in /etc/lvmconf/vg00.conf


i need the words inside the quotes.

like "/dev/vg00/rlvol9" and "/dev/vg00/lvol9"


Regards,
Jenith Christopher
2 REPLIES
Hein van den Heuvel
Honored Contributor
Solution

Re: need a particular word from the file in Korn shell scripting

That's easy enough to do in perl, awk, sed.
It's not too hard in a shell, but if you don't know how already, then why suggest a tool you apparently do not know well enough?

What is the _real_ problem you are trying to solve.
Once you have those pieces of string, then what must be done with them. That may well define the right search method.

What are the constraints.
The 2 example solutions you give are not 'words' by many defintions.
The solutions do not include the "64", but the description would.

So... does such target string have to start with a "/"? should it NOT start with a number? Should a soltuion handle more than 1 match on a single line (how should it react)...

Here is something in PERL to get you going:

$ perl -lne 'print $1 if /"(\/\S+)"/' tmp.txt
/dev/vg00/lvol9
/dev/vg00/rlvol9
/dev/vg00/lvol9

You can easily pipe that into a shell read loop, but I suggest you think about making the perl (or awk or whatever) do more with the strings while it has them!

-l = free linefeed with each print
-n = loop over input file(s) placing lines in $_
-e = program text to follow
$1 = match string between ( )
/.../ = regular expression matching against $_
"\/ = enforce leading '/' after a '"'
\S+ = any non-white-space

Enjoy!
Hein.







Peter Nikitka
Honored Contributor

Re: need a particular word from the file in Korn shell scripting

Hi,

there may be difficulties, when there are more than one such quoted string per line or when there are embedded spaces in them.
Next you don't seem to consider the string "64" of your sample input as valid.

This solution does NOT work for embedded spaces and outputs strings only when they start with 'dev':

awk -v qd='"' '$0 ~ dq {for (i=1;i<=NF;i++) if ($i ~ dq"dev") print $i}' /tmp/lvt

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"