Display output bash program

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 10-18-2010
Display output bash program

Hello, i have a problem with the output from my bash program.

I made this program

Code:
#!/bin/bash

BESTANDEN=$* # Plaatst bestanden in de variabele BESTANDEN
TMPFILE=xmlprog.sh.$$.$RANDOM # basisnaam voor tijdelijke bestanden

# controller of het programma correct is aangeroepen
if [ -z "$BESTANDEN" ]
then
    echo "FOUT: Er zijn geen bestanden opgegeven!" >&2
    exit
fi

for i in "$BESTANDEN" 
do
    # Delete XML TAGS
    sed -e 's/></>\n</g' $i | sed 's/<\/.*>//g' | sed 's/.*\(<.*>\).*/\1/' | sed '/^$/d' | wc -l 
      echo "${i}"
done

With the output:
Code:
28
1000029.xml 1000064.xml

But i need this output:
Code:
22 1000029.xml
6 1000064.xml

Can some one help me?
# 2  
Old 10-18-2010
Remove double quotes " around variable $BESTANDEN

Code:
for i in $BESTANDEN

# 3  
Old 10-18-2010
Thank You, now its working correct.

Code:
20
1000029.xml
8
1000064.xml

One more question, is it possible to get this output:

Code:
20 opening tags in file 1000029.xml
8 opening tags in file 1000064.xml

# 4  
Old 10-18-2010
Code:
#!/bin/bash

BESTANDEN=( "$@" ) ## Put arguments in array
TMPFILE=xmlprog.sh.$$.$RANDOM

if [ $# -eq 0 ] ## If no arguments...
then
    echo "FOUT: Er zijn geen bestanden opgegeven!" >&2
    exit 1
fi

for i in "${BESTANDEN[@]}"
do
    # Delete XML TAGS
    sed -e 's/></>\n</g' $i | sed 's|</.*>||g' | sed -e 's/.*\(<.*>\).*/\1/' -e '/^$/d' | wc -l
    printf "%s\n" "$i"
done

# 5  
Old 10-18-2010
Try this,

Code:
#!/bin/bash

BESTANDEN=$* # Plaatst bestanden in de variabele BESTANDEN
TMPFILE=xmlprog.sh.$$.$RANDOM # basisnaam voor tijdelijke bestanden

# controller of het programma correct is aangeroepen
if [ -z "$BESTANDEN" ]
then
    echo "FOUT: Er zijn geen bestanden opgegeven!" >&2
    exit
fi

for i in $BESTANDEN 
do
    # Delete XML TAGS
echo $(sed -e 's/></>\n</g' $i | sed 's/<\/.*>//g' | sed 's/.*\(<.*>\).*/\1/' | sed '/^$/d' | wc -l) " opening tags in file " $i
done

# 6  
Old 10-18-2010
Alternatively, leave out $BESTANDEN and just use:
Code:
for i in "$@"
do

Also, use:
Code:
sed -e 's/></>\n</g' "$i" ...

# 7  
Old 10-18-2010
Hi Guys, thanks for the replay's,

This solution is working for me right now

Code:
#!/bin/bash

BESTANDEN=$* # Plaatst bestanden in de variabele BESTANDEN
TMPFILE=xmlprog.sh.$$.$RANDOM # basisnaam voor tijdelijke bestanden

# controller of het programma correct is aangeroepen
if [ -z "$BESTANDEN" ]
then
    echo "FOUT: Er zijn geen bestanden opgegeven!" >&2
    exit
fi

for i in $BESTANDEN 
do
    # Verwijderen XML TAGS
    sed -e 's/></>\n</g' $i | sed 's/<\/.*>//g' | sed 's/.*\(<.*>\).*/\1/' | sed '/^$/d' | wc -l > $TMPFILE-1
      echo " XML opening tags in bestand: ${i}" > $TMPFILE-2
    paste -d '' $TMPFILE-1 $TMPFILE-2 
done


rm -f $TMPFILE-1 $TMPFILE-2

But is have a collection of 500+ xml files. So i like to have 10 xml files with the most xml tags.

Can i use something like this?
Code:
paste -d '' $TMPFILE-1 $TMPFILE-2 > $TMPFILE-3
cat $TMFFILE-3 | sort -nr | uniq | head



---------- Post updated at 11:01 AM ---------- Previous update was at 07:47 AM ----------

Hello, i have this solution

Code:
#!/bin/bash
#countxmlprog.sh : telt het aantal xml open tags uit bestanden
# aanroepen als: countxmlprog.sh bestanden
# Auteur: s2065460, frank.spin89@gmail.com

BESTANDEN=$* # Plaatst bestanden in de variabele BESTANDEN
TMPFILE=xmlprog.sh.$$.$RANDOM # basisnaam voor tijdelijke bestanden

# controller of het programma correct is aangeroepen
if [ -z "$BESTANDEN" ]
then
    echo "FOUT: Er zijn geen bestanden opgegeven!" >&2
    exit
fi

for i in $BESTANDEN 
do
    # Verwijderen XML TAGS
    sed -e 's/></>\n</g' $i | sed 's/<\/.*>//g' | sed 's/.*\(<.*>\).*/\1/' | sed '/^$/d' | wc -l > $TMPFILE-1
      echo " XML opening tags in bestand: ${i}" > $TMPFILE-2    
    paste -d ' ' $TMPFILE-1 $TMPFILE-2 >> $TMPFILE-3
done

cat $TMPFILE-3 | sort -nr | head 

rm -f $TMPFILE-1 $TMPFILE-2

This is my right solution.

Can i made a kind of fallback behavior when the user is not entering a file name? Now he gets a error like: "ERROR: NO File"

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Bash Display First Friday of the next month summerdays Linux 7 02-26-2018 08:41 AM
Display the output sreejithalokkan Shell Programming and Scripting 6 10-11-2013 12:41 AM
Bash display error solaris_1977 Solaris 2 06-25-2013 05:25 PM
Bash Info Display kristinu Shell Programming and Scripting 1 09-19-2012 02:46 PM
How to display a message if program hangs(takes too long) mrskittles99 Shell Programming and Scripting 1 07-17-2012 10:45 AM
C program to display a busy symbol while processing rakeshkumar Programming 4 05-05-2012 07:33 AM
Output Display in a perl program mr_manii Shell Programming and Scripting 1 11-29-2011 07:53 AM
To display unique lines in a Program Teju88 Programming 1 07-04-2011 01:08 PM
bash script to display tail LuminalZero Shell Programming and Scripting 11 04-09-2011 03:18 PM
PROGRAM BASH danihj Shell Programming and Scripting 1 02-13-2010 10:11 AM
Command display output on console and simultaneously save the command and its output satimis UNIX for Dummies Questions & Answers 7 01-25-2009 08:27 PM
program or script to display user info flasun Programming 4 01-07-2009 09:31 AM
Display output of one xterm on another Vi-Curious UNIX for Dummies Questions & Answers 8 11-07-2008 04:14 PM
Display a Graphic from a Unix program on a Pc – how? Barry Staples Shell Programming and Scripting 4 02-22-2008 04:43 AM
Display program running on CDE via GNOME navinxavier UNIX for Advanced & Expert Users 4 06-08-2005 10:25 AM