[ask]same but not same (variable and line of file)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ask]same but not same (variable and line of file)
# 1  
Old 09-27-2010
Data [ask]same but not same (variable and line of file)

hi all.
I'm new to bash programming.

I have a problem with compare bash variable and string from text.

for example.
Code:
# I wanted to get maximum page (in this case 16)

cat "page.html" | while read line
do
	# I want to read line with pattern something like this <page>Page 1 of 16</page>
	if [[ $line == *"Page "*" of "* ]]
	then

		# I don't really know how sed or awk works, but I found this command produce what I wanted (16).
		echo $line | sed -e's/<[^>]*>//g' | awk '{print $4}' > "pageCount"
		break
	fi
done

#and then I want to compare content of file with my own variable.
#I'm using this command.

c=$(cat "pageCount")
temp=16

if [[ $c == $temp ]]
then
	echo "same"
else
	echo "different"
fi

I expect the end result will be "same", but actually the result is "different".
how come?

When I echo these two variable, they show same value.

Code:
echo "$c $temp"	#will produce 16 16

I'm really confused now and really need help.Smilie
thanks for helping, and sorry for my bad english.
# 2  
Old 09-27-2010
Post a sample of your html file (with the line containing the page numbers).
There must be a one-liner (i.e with grep) to extract the page count.
Something like
Code:
grep -E '<page>Page [0-9]+ of [0-9+]</page>' page.html

Tell us what's the output of this command.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Assign line from file to variable

Hi, I am new to shell scripting. Need help with the below requirement. I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table. For E.g. file test.sql has below error: ORA-01017:... (3 Replies)
Discussion started by: ricsharm
3 Replies

2. 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

3. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

4. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

5. Shell Programming and Scripting

cut the variable from the line and use it to find the file and read the content of that file

Hi, I am working on one script..I am having files in the below format file 1 (each line is separated with : delimeter) SPLASH:SPLASH:SVN CIB/MCH:MCH:SVN Now I want from file 1 that most left part of the first line will store in... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

6. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

7. Shell Programming and Scripting

substract variable from each line in a file

Hi everyone, I have a file containing one column and I want to subtract the first value (value of first line) from each line's value. 79304 99299 119294 139289 159284 179279 199274 219269 239264 259259 279254 299249 319244 339239 359234I tried working on an awk solution with... (1 Reply)
Discussion started by: ink_LE
1 Replies

8. Shell Programming and Scripting

reading the whole line from a file into a variable

Hi, I am doing : while read line do printf "%s\n" ${line} done <datafile.txt but I am not getting each single line from the data file assigned to the variable line (but only tokens/fields at a time). I also tried while IFS= read -r lineI want the whole line assigned or read into the... (2 Replies)
Discussion started by: shri_nath
2 Replies

9. Shell Programming and Scripting

insert line into file using variable

Hi all, I am trying to insert couple of lines before first occurance of line3 which occuring after line 5. So I identified the line 5 line number in the file. Also redirected the all line3 line number to out.txt. Now I have problem in inserting the line using the variable $rep. Please help me... (2 Replies)
Discussion started by: aimmanuel
2 Replies

10. Shell Programming and Scripting

store the first line of a file in a variable

i have to store the files in a folder and assign a variable to the the files. (0 Replies)
Discussion started by: dineshr85
0 Replies
Login or Register to Ask a Question