Display output bash program


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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  
Remove double quotes " around variable $BESTANDEN

Code:
for i in $BESTANDEN

# 3  
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  
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  
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  
Alternatively, leave out $BESTANDEN and just use:
Code:
for i in "$@"
do

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

# 7  
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"
Login or Register to Reply

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

More UNIX and Linux Forum Topics You Might Find Helpful
C program to display a busy symbol while processing
rakeshkumar
Hi I was wondering how can a c program will be implemented which will display a symbol while calculating something. for example : program should display some charters like /\/\ while calculating. At least provide some pointers thanks... Programming
4
Programming
Output Display in a perl program
mr_manii
Hi All, I have created a sample perl program in one of the unix environment as below #!/usr/bin/perl print "Content-type: text/html\n\n"; print "<H1>Hello World</H1>"; When I execute it in unix, I get the below Content-type: text/html <H1>Hello World</H1> However, when I...... Shell Programming and Scripting
1
Shell Programming and Scripting
To display unique lines in a Program
Teju88
I am new to C programming. I have been trying to display unique lines in a file from past two days. The problem is here, I have a file whose contents are, ras.beamtele.net ras.beamtele.net ras.beamtele.net ras.beamtele.net ras.beamtele.net ras.beamtele.net ras.beamtele.net...... Programming
1
Programming
Display a Graphic from a Unix program on a Pc how?
Barry Staples
An interesting puzzle. I run character based compiled C-Programs in a Unix environment on PCs in a Window. I want to be able to call up and display in a separate window a picture of a product called by a Unix shell script from within my Unix program. Ideally I would like to have a script that...... Shell Programming and Scripting
4
Shell Programming and Scripting
Display program running on CDE via GNOME
navinxavier
Hi All, I have one AIX box (5.1 with CDE running) and one Linux box ( FC3 with GNOME on it). What I want to be able to do is : SSH from the Linux box into the AIX box and then open an X term to launch a X window application. I am not able to do that. My guess is that the window mangers and...... UNIX for Advanced & Expert Users
4
UNIX for Advanced & Expert Users