Script to compare lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to compare lines
# 1  
Old 01-21-2009
Script to compare lines

I need a simple script to parse a file with this data in it and have that script output a warning when CurrCapacity is more that 50% of MaxCapacity for a given pool Name, can anyone help ?

CurrCapacity: 5
MaxCapacity: 20
Name: fhlwDSource
CurrCapacity: 5
MaxCapacity: 20
Name: repositoryDSource
# 2  
Old 01-21-2009
start with this:
Code:
#!/bin/ksh
while read fld1 fld2  dummy
do
	if [[ "$fld1" = "CurrCapacity:" ]] ; then
		   cur="$fld2"
	fi
	if [[ "$fld1" = "MaxCapacity:" ]] ; then
		   max="$fld2"
	fi
	if [[ "$fld1" = "Name:" ]] ; then
		   result=$(( ( $cur * 100 ) / $max ))
		   if [[ $result -gt 50 ]] ; then
				echo "$fld2 is bad $result percent"
		   else
				echo "$fld2 is okay at $result percent"
		   fi
	fi
done < filename

# 3  
Old 01-21-2009
syntax error: `result$=' unexpected

Thanks for the reply but I keep getting this error when I run it ?

syntax error: `result$=' unexpected
# 4  
Old 01-21-2009
init0,

looks to me that you have a typo if you get a syntax error 'result$=' the script assigns a value to 'result' not 'result$'. Check your typing of the script and try again. Looks to me like it should work, I had a similar script in mind but jim beat me to it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare lines between two files

I have two files I need to compare these two files and take the lines that are common in both the files and consider the line present in second file for my further processing I have used "Awk" along with "FNR and NR" but that is not working gawk -F= ' > FNR==NR {a=$1; next}; > ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

2. UNIX for Dummies Questions & Answers

Compare lines in 2 files

I have 2 files with exactly the same information (with header and separated by ";") and what I would like to do is print (for both files!) the columns that are different and also print the "key" column that is equal in the 2 files For example, if File1: key1;aaa;bbb;ccc key2;ddd;eee;fff... (4 Replies)
Discussion started by: mvalonso
4 Replies

3. Shell Programming and Scripting

Script to compare lines in a file

Need help to create the script that does the following : - 1. Compare the current line "column B and C" with next line "column B and C" 2. If they are the same, print output to a file Input file 2014-08-25 04:45:56.673|T1|JO|Begin|10 2014-08-25 04:55:56.673|T1|JO|Begin|11 2014-08-25... (8 Replies)
Discussion started by: chailee
8 Replies

4. Shell Programming and Scripting

How to compare two lines in a csv file using shell script?

I have a file lets say input.csv having two columns like- Name,Mobile No A,111 B,222 A,333 A,123 B,213 I would like to find result in a new file lets say output.csv as- Name,Mobile No A,111 B,222 means short the file on the basis of first column and first value corresponding to the... (5 Replies)
Discussion started by: Ashish Singhal
5 Replies

5. Shell Programming and Scripting

compare lines in a file

Hi Folks, I need to compare the cron's timings from a text file. Need to display how much time does it took for that job. For example i have the below txt file, I have cron1 started at 05:23:15 and completed at 05:25:57, now i need to find how much time did it took to complete corn1 job for... (8 Replies)
Discussion started by: Sendhil.Kumaran
8 Replies

6. Shell Programming and Scripting

Compare lines within a file

could someone write a short script which is able to take a text file input and compare lines 1 and 2, 3 and 4, 5 and 6 ... ... until the end of the file. And to prompt if the lines are not equal. Thank you! (10 Replies)
Discussion started by: c_lady
10 Replies

7. Shell Programming and Scripting

how to compare two lines using shell script?

how to compare two lines using shell script? (1 Reply)
Discussion started by: suman_dba1
1 Replies

8. Shell Programming and Scripting

Compare lines and execute

Greetings, I'm new to scripting and need a little help. I have a NAS server and want to make a script that bans IP if they fail login several times. The problem is that I dont know how to compare the IP's in the file. If they exist more than 3 times do .... #!/bin/sh set -x X=4 rm... (2 Replies)
Discussion started by: ntenz
2 Replies

9. Shell Programming and Scripting

Help! How to compare two lines in a file

Hello, I am newcomer and sorry for this simple question. I want to how to compare two lines in a file? For example, to compare the first line and the second line of a file to know if they are same? Thanks in advance! Leon (3 Replies)
Discussion started by: sabertooth2000
3 Replies

10. Shell Programming and Scripting

Trying to compare lines in 2 files

Hello, I am new to scripting and need some help. In looking at other posts on this forum, I came up with the following logic. I cannot figure out why I am getting names of files of the current directory in my echo output. Scenario: message file has a line containing the version. Version.txt... (2 Replies)
Discussion started by: brdholman
2 Replies
Login or Register to Ask a Question