cut command

cut command

Post by rjpaq.. » Wed, 09 Aug 2000 04:00:00



I am working on a ksh script wherein a table is read in to produce
variables for use on specific files. I am using the cut command to read
specific fields in that table. One of the fields contains unix commands
to be executed on specific files (the ksh script handles several files
with different reformatting requirements). The cut command in question
is:

unix_commands=`echo $line | cut -d":" -f4'

The table entry that echo reads is:

:command $vardir/$varfile.tmp $vardir/tmp.$varfile,command
$vardir/tmp.$varfile $vardir/$varfile.tmp:

(the first "command" reformats the file and outputs it with a new name,
the second "command" performs additional reformatting and restores the
results to the original filename)

The problem is I am not getting the VALUES of $vardir or $varfile, but
am only getting the literal characters "$vardir" and "$varfile". In
other words, the variable $unix_commands, when echoed out, is precisely
the same as the table entry that is read in.

I'm sure this is obvious to your ordinary garden-variety Unix guru, but
that ain't me! ;-)

Obviously, I cannot use the cut command for this function, but am at a
loss as to what I CAN use. Or perhaps I CAN use the cut command, but
have to use some intermediate command to evaluate the values of the
variables before assigning it to a variable I can use later in the
script. Any pointers would be appreciated.

Ron

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

cut command

Post by Mike Cros » Wed, 09 Aug 2000 04:00:00


You need to eval the echo $line to get the shell to expand the variables.

> I am working on a ksh script wherein a table is read in to produce
> variables for use on specific files. I am using the cut command to read
> specific fields in that table. One of the fields contains unix commands
> to be executed on specific files (the ksh script handles several files
> with different reformatting requirements). The cut command in question
> is:

> unix_commands=`echo $line | cut -d":" -f4'

> The table entry that echo reads is:

> :command $vardir/$varfile.tmp $vardir/tmp.$varfile,command
> $vardir/tmp.$varfile $vardir/$varfile.tmp:

> (the first "command" reformats the file and outputs it with a new name,
> the second "command" performs additional reformatting and restores the
> results to the original filename)

> The problem is I am not getting the VALUES of $vardir or $varfile, but
> am only getting the literal characters "$vardir" and "$varfile". In
> other words, the variable $unix_commands, when echoed out, is precisely
> the same as the table entry that is read in.

> I'm sure this is obvious to your ordinary garden-variety Unix guru, but
> that ain't me! ;-)

> Obviously, I cannot use the cut command for this function, but am at a
> loss as to what I CAN use. Or perhaps I CAN use the cut command, but
> have to use some intermediate command to evaluate the values of the
> variables before assigning it to a variable I can use later in the
> script. Any pointers would be appreciated.

> Ron

> Sent via Deja.com http://www.deja.com/
> Before you buy.


 
 
 

cut command

Post by Peter Nikitk » Sat, 12 Aug 2000 04:00:00



> I am working on a ksh script wherein a table is read in to produce
> variables for use on specific files. I am using the cut command to read
> specific fields in that table. One of the fields contains unix commands
> to be executed on specific files (the ksh script handles several files
> with different reformatting requirements). The cut command in question
> is:

> unix_commands=`echo $line | cut -d":" -f4'

> The table entry that echo reads is:

> :command $vardir/$varfile.tmp $vardir/tmp.$varfile,command
> $vardir/tmp.$varfile $vardir/$varfile.tmp:

> (the first "command" reformats the file and outputs it with a new name,
> the second "command" performs additional reformatting and restores the
> results to the original filename)

> The problem is I am not getting the VALUES of $vardir or $varfile, but
> am only getting the literal characters "$vardir" and "$varfile". In
> other words, the variable $unix_commands, when echoed out, is precisely
> the same as the table entry that is read in.

> I'm sure this is obvious to your ordinary garden-variety Unix guru, but
> that ain't me! ;-)

....

You nearly guessed it: The function you need, ist the Shell-builtin
"eval":
value=hello
var='$value'
echo $var
  $val
eval echo $var
  hello

You can use something of this kind for you:
eval `echo $line | cut ...`
   where the echo produces 'command $var1 $var2'

to execute 'command'.

mfg Peter

Ron

Quote:

> Sent via Deja.com http://www.deja.com/
> Before you buy.

--
Quote of the month:
        Perl can do everything Awk can do, but not as elegantly.
 
 
 

1. Help: How to cut last field by CUT command

        Does anyone tell me how to cut only last field in the text line.

For example,

Each line is delimited by `,' and has different number of delimiter;

AAA, BBB, CCC
DDD, EEE
FFF, GGG, HHH, III

I'd liked to get following output

CCC
EEE
III

Thanks in advance
 Haru
--


ZEXEL USA, Inc.   (408) 738-4250 VOICE
265 Santa Ana Ct. (408) 738-4302 FAX  

2. MAC adress question

3. cut command

4. Install 2.5 on SS1+ problem ?

5. NFS via SSH?! (nfs over tcp i need)

6. Help with X and a Trident 9440 2meg PCI Card

7. Need Help Cut Command

8. command for help (cutting lines with blank)

9. Please help with 'cut' command!