Perl find page number in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl find page number in a file
# 1  
Old 05-25-2009
Perl find page number in a file

Hi i want to ask how can i use perl and find a word in a text file, and also telling that which page doesn't it exist?

Eample: have a 10 pages text file, then i need to find 'Hello' in the file, and show that which page is it contain in.

Output: Hello contains 8 times in page 1, 3, 4, 7, 10

Code:
$page = $%;
while (@word)
	{
		while ( /(\w['\w-]*)/g)
		{
			# Increment the counter
			$seen{lc $1}++;
		}
	}

foreach $word (sort { $seen{$a} <=> $seen{$b} } keys %seen)
	{
		print "$word found $seen{$word} times on pages $page\n";
	}

i got something like that, but it is not working. can anyone please help me?
Thank you

Last edited by mingming88; 05-25-2009 at 05:09 AM..
# 2  
Old 05-25-2009
What counts as a 'page'?
# 3  
Old 05-25-2009
page = $%;
is this find out the page??
count for what page?
# 4  
Old 05-25-2009
That works if you're using "write" and format while printing output, but not while processing input.
# 5  
Old 05-25-2009
Quote:
Originally Posted by otheus
That works if you're using "write" and format while printing output, but not while processing input.
can u give me an example, because i don't really understand.
Thank you
# 6  
Old 05-25-2009
I don't either. How do you know your input consists of 10 pages?
# 7  
Old 05-25-2009
Quote:
Originally Posted by otheus
I don't either. How do you know your input consists of 10 pages?
it just for example, of course i don't know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Page number with total number of pages, EG Page 1 of 5

So I've worked how to add page numbers based on regex. It's using the footer text. How do we get the total amount added so we have page number with the total number of pages? Desired output: Page No:1 of 5 Thanks in advance. (15 Replies)
Discussion started by: tugar
15 Replies

2. Programming

Find the number in the file

In my system , there are text files will be generated monthly , the file name begins with xxx , then year , month ( for example xxxxx201310.txt means Oct 2013 ) I have below command to count how many abc in the month , but it only count the number in this month . NUMBER=$(cat xxxxx201310.txt... (2 Replies)
Discussion started by: ust
2 Replies

3. Shell Programming and Scripting

Perl: find next available lowest number that is available in two arrays

Hi there. I have a number allocation problem whereby I have 2 arrays built from 2 different sources. The arrays will just contain a listed of sorted numbers @a 1 7 10 14 15 16 @b 1 7 10 11 14 15 16 (2 Replies)
Discussion started by: hcclnoodles
2 Replies

4. Shell Programming and Scripting

script for adding page number before page breaks

Hi, If there is an expert that can help: I have many txt files that are produced from pdftotext that include page breaks the page breaks seem to be unix style hex 0C. I want to add page numbers before each page break as in : Page XXXX Regards antman (9 Replies)
Discussion started by: antman
9 Replies

5. Shell Programming and Scripting

Perl - how to find the number based on the same name

Hi Perl Experts, Could somebody help me how to solve my problem if I have array contains the following data: "SEQ-0 UNSORT2 0", "SEQ-1 UNSORT2 1", "SEQ-2 UNSORT2 2", "SEQ-3 UNSORT2 3", <--- Missing the... (0 Replies)
Discussion started by: askari
0 Replies

6. Shell Programming and Scripting

Perl extract number from file & write to file

I have 1 file that has elements as follows. Also the CVR(10) and the word "SAUCE" only appear once in the file so maybe a grep command would work? file1 CVR( 9) = 0.385E+05, ! VEHICLE CVR(10) = 0.246E+05, ! SAUCE CVR(11) = 0.162E+03, ! VEHICLE I need to extract the... (6 Replies)
Discussion started by: austinj
6 Replies

7. Shell Programming and Scripting

Using perl code find greatest number.

How would one go about finding the greatest number in an array of numbers using loops and if statements? For example, if you had an array like this: (4, 8, 3, 19, 6, 11) (3 Replies)
Discussion started by: DemonixX
3 Replies

8. UNIX for Dummies Questions & Answers

Find number of columns in a file

Hi all, may seem a very stupid question.but me stuck up in it for long.... How to find the number of columns in a ASCII file. EX:-Demo.lst songs 1 34 45 67 Number of columns should be 5. Regards, Anindya ;) (13 Replies)
Discussion started by: rahul26
13 Replies

9. Shell Programming and Scripting

How to find number of lines in a file

Hi How do I find number of lines of a file? Below commands returned 0. But, the file is showing 20 lines when I open it in editplus tool. Each line contains 601 columns. Please advise I want to incorporate some word at the begining of each of those 20 lines -Somesh $ wc -l <... (2 Replies)
Discussion started by: somesh_p
2 Replies

10. Shell Programming and Scripting

find the highest number in the file

Hi, I have a file a.txt and it has values in it Eg :- I need to read through the file and find the number that is the greatest in them all. Can any one assit me on this. Thanks (30 Replies)
Discussion started by: systemali
30 Replies
Login or Register to Ask a Question