Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I'm a unix beginner. How can I

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I'm a unix beginner.
How can I check a html file whether all the tags are balanced or not. If balanced, it'll show a message of "Balance" else "Not balance".
What should I type? use awk command?
pls help.
 
Shouldn't be to hard, but your going to have to write a shell script to do this. Assuming you always use closing tags for everything that has one, try this:

CountTags.ksh
#!/usr/bin/ksh -p

# Script designed to count opening tags and closing tags

FILE=$1

# C(number) stands for Count Variable
C1=`/usr/bin/grep &quot;<HTML>&quot; ${FILE}`
C2=`/usr/bin/grep &quot;</HTML>&quot; ${FILE}`
C3=`/usr/bin/grep &quot;<HEAD>&quot; ${FILE}`
C4=`/usr/bin/grep &quot;</HEAD>&quot; ${FILE}`
etc,etc

print &quot;Count for <HTML> Tags: ${C1}.&quot;
print &quot;Count for </HTML> Tags: ${C2}.&quot;
print &quot;Count for <HEAD> Tags: ${C3}.&quot;
print &quot;Count for </HEAD> Tags: ${C4}.&quot;



That should do what you want, you could probably put this into a for loop format so you wouldn't have to type out all of the variables. Maybe something like this:
FILE=$1
COUNT=1

# SOMENUMBER == # of Tags that you check for.
let SOMENUMBER=SOMENUMBER+1
while [ ${COUNT} -ne ${SOMENUMBER} ]
do
for VAR in HTML HEAD TITLE P BLOCKQUOTE (ETC,ETC)
do
C${COUNT}=`/usr/bin/grep &quot;<${VAR}>&quot; ${FILE}
let COUNT=COUNT+1
C${COUNT}=`/usr/bin/grep &quot;</${VAR}>&quot; ${FILE}
done
let COUNT=COUNT+1
done


Not sure if the second example will work right off the bat, may need some work, but the first one should be good to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top