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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing values from a file - string

Status
Not open for further replies.

areza123

Programmer
Jul 4, 2002
60
IN
I have a file with the format
(name of the file is old_ls_out )
14:00 config
18:01 abc
17:43 dsd
17:29 test134.txt

I want to initialize the file time and file name to 2 separate variables.In my shell script I use the code

LATEST_ARCHIVED_FILE_TIME = head -1 old_ls_out | nawk '{print $1}'
echo "Latest archived file time $LATEST_ARCHIVED_FILE_TIME "
LATEST_ARCHIVED_FILE_NAME = head -1 old_ls_out | nawk '{print $2}'
echo "Latest archived file name $LATEST_ARCHIVED_FILE_NAME "

I expect the output

Latest archived file time 14:00
Latest archived file name config

But instead what I get is

fm1[2]: LATEST_ARCHIVED_FILE_TIME: not found
Latest archived file time
fm1[4]: LATEST_ARCHIVED_FILE_NAME: not found
Latest archived file name

What is wrong with the code above ?

Cheers !
 
You've got spaces between the variables and the = signs.
You also need ` (back-ticks) for the commands :
LATEST_ARCHIVED_FILE_TIME=`head -1 old_ls_out | nawk '{print $1}'`
LATEST_ARCHIVED_FILE_NAME=`head -1 old_ls_out | nawk '{print $2}'`

HTH

Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top