The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Line by line file reading... and more! ProFiction Shell Programming and Scripting 6 07-26-2007 11:32 AM
Reading line by line from a file tej.buch Shell Programming and Scripting 2 01-23-2006 02:50 AM
Reading line of text nhatch Shell Programming and Scripting 2 09-27-2005 02:23 AM
paging a text file line by line? tomapam UNIX for Dummies Questions & Answers 2 10-07-2002 09:30 AM
Reading line by line from file. akpopa UNIX for Dummies Questions & Answers 4 08-30-2001 10:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2005
MizzGail's Avatar
MizzGail MizzGail is offline
Registered User
  
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 164
reading text file line by line

Ok. before anyone mentions it, I did search for this but I'm not sure if I am looking for the right thing.
Now, onto my issue.
I have been keeping vmstats output in running text files.
So I have a file that looks like this:
vmstat 2 5
2005.09.19[00:04:09]

kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 s1 s2 s3 in sy cs us sy id
0 0 0 26713952 3406744 104 360 180 2 1 0 0 0 1 0 1 3384 3338 2518 10 8 82
0 0 0 27029440 3694096 0 47 107 0 0 0 0 0 0 0 0 27724 18857 23609 20 12 6
8
0 0 0 27026376 3692096 257 1438 251 4 4 0 0 0 1 0 0 28839 24707 23954 24 18 5
8
0 0 0 27026304 3692424 0 0 24 0 0 0 0 0 1 0 0 26233 17749 23187 15 11 7
5
0 0 0 27025320 3691368 0 61 16 0 0 0 0 0 1 0 0 27644 18792 24070 18 14 6
8


For my own purposes, I echo in the command that I am issuing which was vmstat 2 5. then I put in a date stamp. Each time I run my capture stats process it appends to the text file for that day.
I need to now put these in an excel sheet for someone non-technical to use for another project.

I need to take each line of the text file and tag the date on the front or end.
I started with the following script but when I run it I get the error:
./fmtstats.ksh[12]: = 2005 : assignment requires lvalue

#!/bin/ksh
set -x
statfile=/export/home/myfiles/vmstats.2005.09.19
kyr=2005
kwrd=vmtstat
cat $statfile | while read a
do
fld1=`echo $a | awk -F: '{print $1}'`
echo " "
echo $fld1
sleep 1
if (($fld1 = $kyr )); then
echo "date found "
else
echo $fld1 $a >> new.output.file
fi
done


My plan is to identify $fld1 as the date, then look just concatenate it with the following lines until I hit the value of the date again.

I'm sure there is a gross mistake here someplace, but I can't find what lvalue is.

OH. I'm on sun solaris 9
  #2 (permalink)  
Old 09-19-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
lvalue means a place to put something while rvalue means something that has a value. The l means left and the r means right. And those are the two sides of an assignment statement.:
x=7
x is an lvalue, a place to put something. It ok if x does not have a value yet.
7 is a rvalue.

This is illegal:
((7=7))
The 7 of the left is not a place to put something so it not a (valid) lvalue. Type ((7=7)) at your shell prompt and you will get that error message.

You are doing this in your script with the if statement. Change = to == to fix it.
  #3 (permalink)  
Old 09-19-2005
MizzGail's Avatar
MizzGail MizzGail is offline
Registered User
  
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 164
+ sleep 1
+ (( == 2005 ))
./fmtstats.ksh[12]: == 2005 : syntax error
$

AH. its possible that it doesn't like that the $fld1 is blank when its not on the date record?
  #4 (permalink)  
Old 09-19-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
You would be better off with this style:
if [[ $a = $b ]] ; then
  #5 (permalink)  
Old 09-19-2005
MizzGail's Avatar
MizzGail MizzGail is offline
Registered User
  
 

Join Date: Sep 2001
Location: Syracuse, NY
Posts: 164
Thank, that takes care of that piece!
  #6 (permalink)  
Old 04-14-2008
psalas psalas is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 19
Quote:
Originally Posted by MizzGail View Post
Thank, that takes care of that piece!
HELP! I HAVE A PROBLEM. I HAVE a file like this:
date FINAL RESULT: 6
date FINAL RESULT: 4
date FINAL RESULT: 8
...

I want to read the file and make the average of the Final Results(6,4,8 etc). how can i do that?
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0