Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Number of columns in xml file

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-08-2013
victory victory is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 13 July 2015, 8:32 AM EDT
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Number of columns in xml file

How to find the number of columns in xml file.

i tried following command.

Code:
#!bin/ksh
cat $1 | grep -c "</mdm:attribute>"
exit 0

but i am not getting accurate result which is not matching with the manual count.
data format :

Code:
<mdm:attribute> value </mdm:attribute>


Last edited by Franklin52; 01-08-2013 at 08:36 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old Unix and Linux 01-08-2013
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 6 January 2016, 2:44 AM EST
Location: ./India/Bangalore
Posts: 1,239
Thanks: 58
Thanked 283 Times in 276 Posts
Hope this will help you ..


Code:
perl -nle 'print $1 if /<\/(.+?)\>/g' file.xml | wc -l

Sponsored Links
    #3  
Old Unix and Linux 01-08-2013
victory victory is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 13 July 2015, 8:32 AM EDT
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
It's not perl script it is UNIX ibm aix.
    #4  
Old Unix and Linux 01-08-2013
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 16 December 2015, 5:59 AM EST
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 627 Times in 584 Posts
Quote:
Originally Posted by victory View Post
... it is UNIX ibm aix.
Did you try to execute the above command?
Sponsored Links
    #5  
Old Unix and Linux 01-08-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 4 February 2016, 3:16 PM EST
Location: Saskatchewan
Posts: 21,181
Thanks: 938
Thanked 3,813 Times in 3,557 Posts
xml doesn't have "columns" per se so I'm not really sure what you want. Could you show a more complete input file and what you're expecting to get from it?
Sponsored Links
    #6  
Old Unix and Linux 01-08-2013
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 August 2015, 4:23 PM EDT
Location: Houston, Texas, USA
Posts: 685
Thanks: 0
Thanked 207 Times in 199 Posts
try also:

Code:
awk '{c+=gsub("</mdm:attribute>","&")} END {print c}' file.xml

Sponsored Links
    #7  
Old Unix and Linux 01-08-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 1 February 2016, 3:35 PM EST
Location: Southern NJ, USA (Nord)
Posts: 4,673
Thanks: 8
Thanked 587 Times in 560 Posts
The grep counts lines with matches, not matches. Preprocess the file so every > becomes a line feed and grep for "</mdm:attribute$".
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
concatenate 'n' number of columns in a file mlpathir Shell Programming and Scripting 3 10-06-2010 08:24 PM
Find number of columns in a file rahul26 UNIX for Dummies Questions & Answers 13 05-08-2009 06:11 AM
Counting number of columns in a delimited file net Shell Programming and Scripting 4 03-05-2009 04:56 AM
extract a number within an xml file tret Shell Programming and Scripting 10 10-07-2008 08:10 PM
Cutting number from range in xml file nir_s Shell Programming and Scripting 4 07-25-2005 03:38 AM



All times are GMT -4. The time now is 09:25 AM.