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.
Shahul
February 18, 2009, 2:22am
2
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
Sha:)
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
Sha:)
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
Shahul
February 18, 2009, 2:28am
4
Please try now and let me know
#!/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]>"
Thank you again . Same result
however: grep -l "<[A-Z]>" *.html
works flawlessly
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
Try this
grep -l "\<[A-Z]\>" *.html
Shahul
February 18, 2009, 2:36am
8
Oops..
sorry i was doing some other things...
below one should definetely work.. ...
#!/bin/sh
for x in *.html
do
cat $x | grep "<[A-Z]>"
if [ $? -eq "0" ]
then
echo $x
fi
done
Thanks
Sha
This works, but my understanding is with this expression:
echo $x | grep "<[A-Z]>"
if [ $? -ge "0" ]
then
echo $x
fi
Should only print the file name "$x" if in fact it contains a capital tag.
The cat $x | grep "<[A-Z]>"
Results with :
sh-3.2$ ./qt6.sh
test_1.html
test_2.html
<P>testtesttest</P>
test.html
sh-3.2$
Expected:
sh-3.2$ ./qt6.sh
<P>testtesttest</P>
test.html
sh-3.2$
Thank you everyone.
Sorry one more question!
If I wanted to check for :
<H1> </H1>
or <H12> </H12>
I've tried these:
grep -l "\<[A-Z]?[0-9]+\>" *.html
Am I going in the right direction?
Try like this
grep -l "\<.*[A-Z].*\>" *.html
This should match lines which are having any capital letter between < and >
Regards
Ranjith