How to know which pages don't have...?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to know which pages don't have...?
# 1  
Old 07-26-2012
How to know which pages don't have...?

Hi & good day UNIX / Linux folks,

Some of my > 700 pages don't have this counter:

Code:
 <!--#exec cgi="/cgi-bin/counter"-->

How would one use find (?!) to know which pages _don't have_ this counter, or - alternatively - which don't have the string:

Code:
 exec cgi

(=bec. probably easier, "exec\ cgi")

for our *.html pages in folder chu/

Any advice welcome!

bw, Omar KN
(is this "verbose"?)
# 2  
Old 07-26-2012
Please get into the habit of posting what Operating System and version you have and what Shell you use.
Any clues about how to identify your files. Are they all with extension .html for example?
Based on the example provided, is this special line on it's own in a single-line file or perhaps somewhere else in each file?
# 3  
Old 07-26-2012
Quote:
Originally Posted by methyl
...Operating System... Shell ... line
Yes, this is for Mac OSX, bash, and a single line between other HTML-tags, mostly somewhere else in each file.
They are all html files.

/ okn
# 4  
Old 07-27-2012
If you install this script in $HOME/bin/no_cgi:
Code:
#!/bin/bash
if ! grep -q "exec cgi" "$1"
then    printf 'No "exec cgi" in %s\n' "$1"
fi

and make it executable:
Code:
chmod +x $HOME/bin/no_cgi

You can then run the command:
Code:
find chu -name '*.htm*' -exec $HOME/bin/no_cgi {} \;

to get a list of html files that don't contain the string "exec cgi". (This assumes that all of your html files have names ending in .htm or .html. If you have html files with other filename suffixes, adjust the -name find primary operand as needed.)

If there aren't any subdirectories under chu, you don't need to use find. In this case, replace $HOME/bin/no_cgi with:
Code:
#!/bin/bash
for i in *.htm*
do
    if ! grep -q "exec cgi" "$i"
    then    printf 'No "exec cgi" in %s\n' "$i"
    fi
done

and then run:
Code:
cd chu
$HOME/bin/no_cgi

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 07-28-2012
Hi Don ,

Thank you, I installed this script as described, and made it executable.

And it worked!

My first script, and I let it write out a little file adding:


Code:
 | cat > no_cgi.txt

What can I say, really cool stuff!

bw, Omar KN
Sth, Sweden
# 6  
Old 07-28-2012
Quote:
Originally Posted by Don Cragun
If you install this script in $HOME/bin/no_cgi:
Code:
#!/bin/bash
if ! grep -q "exec cgi" "$1"
then    printf 'No "exec cgi" in %s\n' "$1"
fi

...<snip>...
Code:
find chu -name '*.htm*' -exec $HOME/bin/no_cgi {} \;

to get a list of html files that don't contain the string "exec cgi". (This assumes that all of your html files have names ending in .htm or .html. If you have html files with other filename suffixes, adjust the -name find primary operand as needed.)
That's an unnecessarily inefficient solution. There's no need to invoke bash for each file. We can just use grep directly.

Also, the pattern used with -name, *.htm*, can match more than just .htm and .html files. *.htm? would be better, but could still match something undesirable.
Code:
find chu -type f \( -name '*.htm' -o -name '*.html' \) ! -exec grep -q 'exec cgi' {} \; -print

Regards,
Alister

---------- Post updated at 12:42 AM ---------- Previous update was at 12:40 AM ----------

Quote:
Originally Posted by OmarKN
My first script, and I let it write out a little file adding:

Code:
 | cat > no_cgi.txt

What can I say, really cool stuff!
You don't need to pipe the results of the script into cat just to redirect the output to a file. You can do the redirection directly.
Code:
> no_cgi.txt

Congratulations on your first script. I hope you continue to enjoy the learning curve. Smilie

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 7  
Old 07-28-2012
Interesting!

And - to shorten - if are all html files (none htm ) then:

Code:
 find chu -type f \( -name '*.html' \) ! -exec grep -q 'exec cgi' {} \; -print

ok, I just added:

Code:
  > no_cgi2.txt

bw,
Omar KN

Last edited by OmarKN; 07-28-2012 at 01:57 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. HP-UX

Looking for some man pages.

Can anyone supply me with the man pages for: omnidatalist omnibarlist omnisap.exe I prefer the source man pages in nroff format. A clue about the software bundles which supply these man pages is fine as well. OS: HP-UX TIA (11 Replies)
Discussion started by: sb008
11 Replies

2. Solaris

MAN PAGES

Hi everyone, I have a small query, in solaris the man pages get displayed on half of the terminal , can i get a full terminal or full screen display ?:) (2 Replies)
Discussion started by: M.Choudhury
2 Replies

3. UNIX for Dummies Questions & Answers

pages out

okay.. have monitored that the page out/h max and avg have been 0 for one week. is this possible...? huge applications will have swap space being utilised ... so i am suprised that for one whole week, it has actually been zero please advise thanks (1 Reply)
Discussion started by: yls177
1 Replies

4. UNIX for Dummies Questions & Answers

man pages

When reading man pages, I notice that sometimes commands are follwed by a number enclosed in parenthesis. such as: mkdir calls the mkdir(2) system call. What exactly does this mean? (4 Replies)
Discussion started by: dangral
4 Replies

5. UNIX for Dummies Questions & Answers

man pages

Hi folks, I want to know all the commands for which man pages are available. How do i get it? Cheers, Nisha (4 Replies)
Discussion started by: Nisha
4 Replies

6. UNIX for Advanced & Expert Users

wired pages

hi, can any body tell, what are wired pages in HP_UX. which structure contains that and plz tell the corresponding system call to get it. (1 Reply)
Discussion started by: venkat_t
1 Replies

7. UNIX for Dummies Questions & Answers

man pages

Hi, I've written now a man pages, but I don't knwo how to get 'man' to view them. Where have I to put this files, which directories are allowed?? THX Bensky (3 Replies)
Discussion started by: bensky
3 Replies

8. UNIX for Dummies Questions & Answers

Man pages

Hello , I just installed openssh in my system . I actually tried to man sshd but it says no entry , though there is a man directory in the installation which have the man pages for sshd . Can anyone tell me how should i install these man pages . DP (2 Replies)
Discussion started by: DPAI
2 Replies
Login or Register to Ask a Question