Sponsored Content
Top Forums Shell Programming and Scripting reading text file line by line Post 83765 by MizzGail on Monday 19th of September 2005 01:50:32 PM
Old 09-19-2005
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
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading a file line by line and processing for each line

Hi, I am a beginner in shell scripting. I have written the following script, which is supposed to process the while loop for each line in the sid_home.txt file. But I'm getting the 'end of file' unexpected for the last line. The file sid_home.txt gets generated as expected, but the script... (6 Replies)
Discussion started by: sagarparadkar
6 Replies

2. Shell Programming and Scripting

Reading data from a specific line in a text file

hello, I have got the following problem that I am hoping someone can help with please. 1. I have got the following text file (below) , the columns data are 'Test Day', 'Board', 'Betting Number'. TEXT FILE ============================================ 1 3 02-01-27-28-29-30 0 1... (1 Reply)
Discussion started by: jermaine4ever
1 Replies

3. Shell Programming and Scripting

Reading data from a specific line in a text file

Hello, I have a problem which is giving me headache for days, can some please help. Please see code and text fiel below. Please see text in red for the problem I am facing # Program gets an input x from user while read line ; do echo... (4 Replies)
Discussion started by: jermaine4ever
4 Replies

4. Shell Programming and Scripting

Insertion New line whilst reading the text file

Hi, For the text file let us say t.txt having the statements as below. filename : t.txt. Contents : This is first string1 This is first string2 This is first string3 The output of the file should have newline. How to introduce the new line so that the output be as follows ... (5 Replies)
Discussion started by: krackjack
5 Replies

5. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

6. Shell Programming and Scripting

reading line by line from a text file

Hi, I have a text file something like this: 10.10.10.1, ldap, cn=users,dc=example,dc=com ..... ... and many more lines ... ... now i want to read each individual line from the file and assign it to a variable example: the script should read 10.10.10.1 and assign it to a variable say... (3 Replies)
Discussion started by: sunrexstar
3 Replies

7. Shell Programming and Scripting

EXPECT: Assign variable by reading a line of text from a file

Hi All, I have been using a program on windows called AutoKey. My environment at work is Linux and I have been experimenting with expect. Very powerful. I can move my AutoKey scripts to Linux using Expect once I am educated on how to read from a file using Expect. My application would be... (1 Reply)
Discussion started by: quemalr
1 Replies

8. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

9. Shell Programming and Scripting

Problem with while loop reading every line of a text file

Hello, I'm using RHEL 5.1 with bash. How to handle "read" inside while loop reading every line? Please see below: # cat /tmp/passwd_sample CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash... (4 Replies)
Discussion started by: reddyr
4 Replies
print(1)							   User Commands							  print(1)

NAME
print - shell built-in function to output characters to the screen or window SYNOPSIS
ksh print [ -Rnprsu [n]] [arg...] DESCRIPTION
ksh The shell output mechanism. With no flags or with flag - or -, the arguments are printed on standard output as described by echo(1). OPTIONS
The following options are supported: -n suppresses new-line from being added to the output. -R -r (raw mode) ignore the escape conventions of echo. The -R option will print all subsequent arguments and options other than -n. -p causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. -s causes the arguments to be written onto the history file instead of standard output. -u [ n ] flag can be used to specify a one digit file descriptor unit number n on which the output will be placed. The default is 1. EXIT STATUS
The following exit values are returned: 0 Successful operation. >0 Output file is not open for writing. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
echo(1), ksh(1), attributes(5) SunOS 5.10 15 Apr 1994 print(1)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy