word counts for a single line xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting word counts for a single line xml file
# 1  
Old 10-26-2011
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,
# 2  
Old 10-26-2011
Hi pred,

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

Grettings
This User Gave Thanks to Ophiuchus For This Post:
# 3  
Old 10-26-2011
Code:
grep -o "<TABLE-ROW>" input_file | wc -l

Similar Post
https://www.unix.com/shell-programmin...text-file.html

--ahamed

PS : Please use code tags! Thank You
# 4  
Old 10-26-2011
awk works...

Thank you Ophiuchus.Smilie
# 5  
Old 10-26-2011
Your welcome. Glad it works.

Grettings
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

2. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

3. Shell Programming and Scripting

Grepping a word from a .xml file dynamically

Hi I have the xml file as <Head="Test" Id="3" > <Title="mode" > I have used the code to grep the words "Test" and "mode" as Head=`cat file.xml | grep "Head" | awk -F "=" '{print $2}' | awk -F " " '{print $1}'` Tilte=`cat file.xml | grep "Title" | awk -F "=" '{print... (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

4. Shell Programming and Scripting

Grepping a word from a .xml file

Hi I have a xml file vi lpower.xml <head = power_health> Now, I need to grep "power_health" alone from that file using shell.. Please help (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

5. Shell Programming and Scripting

how to add single digit in front of the word and line in the file.

Hi , how to add the single digit to front of the word and front of the lines in the one file with compare pattern file and get digit. like example pattern file pattern.txt pattern num bala 2 raja 3 muthu 4 File Name: chennai.dat muthu is good boy raja is bad boy selvam in super... (6 Replies)
Discussion started by: krbala1985
6 Replies

6. Shell Programming and Scripting

Search for word in a xml file and replace it with something else

Hello Unix Users, I am very new to Unix so I am not sure how do I do the following. I need a script such that when I type the following in the command prompt > . scriptName.sh wordToBeReplaced DirectoryLocation will find the word someword located in a somefile.xml in DirectoryLocation... (8 Replies)
Discussion started by: 5211171
8 Replies

7. Shell Programming and Scripting

Counts a number of unique word contained in the file and print them in alphabetical order

What should be the Shell script that counts a number of unique word contained in a file and print them in alphabetical order line by line? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

8. Shell Programming and Scripting

Looking for a single line to count how many times one character occurs in a word...

I've been looking on the internet, and haven't found anything simple enough to use in my code. All I want to do is count how many times "-" occurs in a string of characters (as a package name). It seems it should be very simple, and shouldn't require more than one line to accomplish. And this is... (2 Replies)
Discussion started by: Shingoshi
2 Replies

9. Shell Programming and Scripting

adding single word to multiple line.

I have following problem. <File A> contains let say 5 lines but can be changed. cat dog fish car if I want to add word to each line then how do I go about it? I used paste -d but that requires two files having same number of lines but in my case <File A> changes and I just need to... (6 Replies)
Discussion started by: paulds
6 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question