GREP a directory to check for uppercase


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GREP a directory to check for uppercase
# 1  
Old 02-18-2009
GREP a directory to check for uppercase

Hello All,


I am trying to write a script to search in my current directory to look for all files that end with HTML and look for any HTML tags that are in upper case. for example if I were to grep test.html and test.html has a tag <P> instead of <p> then it would print the file name. This is what I have:


#!/bin/sh

for x in *.html

do
echo $x | grep \<[A-Z]+\>
if [ $? -ge "1" ]
then
echo $x
fi
done




thank you in advance.
# 2  
Old 02-18-2009
Hi Raw,

Try this one..hope this should work..

#!/bin/sh
for x in *.html
do
echo $x | grep -l "<[A-Z]>"
if [ $? -ge "0" ]
then
echo $x
fi
done

oR

You can use like ..

grep -l "<[A-Z]>" *.html

this will print all the file name which has upper case tab inside...

Thanks
ShaSmilie
# 3  
Old 02-18-2009
Quote:
Originally Posted by Shahul
Hi Raw,

Try this one..hope this should work..

#!/bin/sh
for x in *.html
do
echo $x | grep -l "<[A-Z]>"
if [ $? -ge "0" ]
then
echo $x
fi
done

oR

You can use like ..

grep -l "<[A-Z]>" *.html

this will print all the file name which has upper case tab inside...

Thanks
ShaSmilie

Hello Shahul,

Thank you for your response and help.

With the edited changes it does not work.

Lets say I have a directory of:

uppercase.sh
test_0.html --- File has <P> capital tag
test_1.html --- File has no capital tags
test_2.html --- File has no capital tags

The output result is as follows:

test_0.html
test_1.html
test_2.html

Expected Result: ( I could be wrong)

test_0.html test_0.html
test_1.html
test_2.html
# 4  
Old 02-18-2009
Please try now and let me know Smilie

#!/bin/sh
for x in *.html
do
echo $x | grep "<[A-Z]>"
if [ $? -eq "0" ]
then
echo $x
fi
done

Thanks
Sha
# 5  
Old 02-18-2009
Quote:
Originally Posted by Shahul
Please try now and let me know Smilie

#!/bin/sh
for x in *.html
do
echo $x | grep "<[A-Z]>"
if [ $? -eq "0" ]
then
echo $x
fi
done

Thanks
Sha

I think you mean

cat $x | grep "<[A-Z]>"
not
echo $x | grep "<[A-Z]>"
# 6  
Old 02-18-2009
Quote:
Originally Posted by Shahul
Please try now and let me know Smilie

#!/bin/sh
for x in *.html
do
echo $x | grep "<[A-Z]>"
if [ $? -eq "0" ]
then
echo $x
fi
done

Thanks
Sha
Thank you again Smilie. Same result Smilie

however: grep -l "<[A-Z]>" *.html
works flawlessly Smilie

Not sure why:
#!/bin/sh

for x in *.html

do
echo $x | grep "<[A-Z]>"
if [ $? -ge "0" ]
then
echo $x
fi
done


Doesn't work Smilie
# 7  
Old 02-18-2009
Try this

grep -l "\<[A-Z]\>" *.html
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory check

How can i check in shell script if the file is coming from same directory as previous file. (3 Replies)
Discussion started by: Pratiksha Mehra
3 Replies

2. Shell Programming and Scripting

How to grep all the files inside the directory and Sub directory

Hi, I have used the command cat * | grep -r <<String>> * It returns: cat : JAN : is directory *********************** ********************* My directory structure: log - JAN -catalina.out -FEB -catalina.out -MARCH ... (11 Replies)
Discussion started by: nanthagopal
11 Replies

3. Shell Programming and Scripting

How to find all files which has names in uppercase in a directory

i want to display all the files which has their names in the Uppercase in a particular directory...guide.. (6 Replies)
Discussion started by: sheelsadan
6 Replies

4. Shell Programming and Scripting

Check whether a string begin with uppercase, lowercase or digit!

Hi every body! I wrote script on Fedora (bash shell) to check whether a tring enter from user console is start with a uppercase/lowercase letter or a digit. But with this script i have some problem when I enter from character from 'b' to 'z' --> result is uppercase. This code look like ok but i... (9 Replies)
Discussion started by: nguyendu0102
9 Replies

5. Shell Programming and Scripting

check for directory

Hi trying to read directory name and compare if exist or not,haw can I do that thanks #!/bin/bash echo -n "Enter: " read var find . -name "$var" -type f (8 Replies)
Discussion started by: lio123
8 Replies

6. Shell Programming and Scripting

Check for a New Directory

Well, I know I could use a cron job to check if a new directory is made. However, I know that it won't happen like every 5 minutes and would be waste of resources. I was wondering is there a better way to check if a new directory is made in a certain folder without a cron job. I do not want it to... (3 Replies)
Discussion started by: almeidamik
3 Replies

7. UNIX for Dummies Questions & Answers

WebDav/davfs mounted file & directory names in all UPPERCASE

Hey, I have a WebDav directory mounted and everything seems fine except for one thing. All file/directory names appear in all UPPERCASE, when in actual fact they are lowercase on the remote machine. For example: foo/bar/baz.html on the remote host, appears on my local machine as... (0 Replies)
Discussion started by: MrMoney
0 Replies

8. UNIX for Dummies Questions & Answers

using grep and to remove all word with uppercase

I try to write a small script that looks in the file tt for all the words that start with m in lowercase and in which there is no uppercase. #!/bin/sh grep ^m\.*\.\.* tt (4 Replies)
Discussion started by: cfg
4 Replies

9. UNIX for Dummies Questions & Answers

Need to change filenames in a particular directory from lowercase to UPPERCASE

Hi, I need a shell script which changes a bunch of files in a particular directory from lowercase to UPPERCASE. I am not very familiar with shell scripts so a detailed explanation would be greatly appreciated!!!! Thanks ini advance! :) (7 Replies)
Discussion started by: Duke_Lukem
7 Replies

10. UNIX for Dummies Questions & Answers

how to check for a directory

Hi, what is the command to in unix shell to find whether a particular direcory is existing or not ? example: i am now in ~/scripts directory and want to find if a direcory called 'log' exists or not from a shell scripts. can somebody please help. thanks, sateesh (3 Replies)
Discussion started by: kotasateesh
3 Replies
Login or Register to Ask a Question