word counts for a single line xml file

I have any XML ouput file(file name TABLE.xml), where the data is loaded in A SINGLE LINE, I need help in writting a ksh shell script which gives me the word counts of word <TABLE-ROW>

This is my input file.

<?xml version="1.0" encoding="UTF-8"?><!--Generated by Ascential Software Corporation, DataStage - XMLOutput stage - Tue Oct 25 11:22:28 2011 --><TABLE><TABLE-ROW><S_NO>1</S_NO><REP_TYPE>TEST1</REP_TYPE><PROCESS_OFFICE>P</PROCESS_OFFICE><PACKAGE_LEVEL>C</PACKAGE_LEVEL></TABLE-ROW><TABLE-ROW><S_NO>2</S_NO><REP_TYPE>TEST2</REP_TYPE><PROCESS_OFFICE>L</PROCESS_OFFICE><PACKAGE_LEVEL>C</PACKAGE_LEVEL></TABLE-ROW><TABLE-ROW><S_NO>3</S_NO><REP_TYPE>TEST3</REP_TYPE><PROCESS_OFFICE>L</PROCESS_OFFICE><PACKAGE_LEVEL>C</PACKAGE_LEVEL></TABLE-ROW></TABLE>

This script (cat TABLE.xml | grep "<TABLE-ROW>" | wc -w) is giving me wrong answer,

Hi pred,

Try with:

awk 'BEGIN{RS=">"} /<TABLE-ROW/{c++}END{print c}' TABLE.xml

Grettings

1 Like
grep -o "<TABLE-ROW>" input_file | wc -l

Similar Post

--ahamed

PS : Please use code tags! Thank You

awk works...

Thank you Ophiuchus.:slight_smile:

Your welcome. Glad it works.

Grettings