Display output bash program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display output bash program
# 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"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Bash display error

Some of my admin made some changes on my Solaris-10 box and after that I started getting this wiered issue. I checked path, but not able to figure it out. This is for a non-root user gcadmin@brbpod06: $ echo $SHELL /usr/bin/bash gcadmin@brbpod06: $ bash bash: brbpod06:: command not found... (2 Replies)
Discussion started by: solaris_1977
2 Replies

2. Shell Programming and Scripting

Bash Info Display

I have written the following bash function prArgv Suppose the calling sequence is as follows prArgv VAL1 VAL2 DESC VAL3 VAL4 v2d1 s4 p15 The call will look at the tag k1v2, add the numbers together, in this case 2+1=3 This means that the function will look at the first 3 user arguments... (1 Reply)
Discussion started by: kristinu
1 Replies

3. Shell Programming and Scripting

How to display a message if program hangs(takes too long)

I have a ksh script (script1) that calls another ksh script (script2). If script2.ksh hangs or takes too long to execute I want script1.ksh to kill the call to script2.ksh and instead just display "Script2 can't run right now". Could someone help me with coding this? (1 Reply)
Discussion started by: mrskittles99
1 Replies

4. Programming

C program to display a busy symbol while processing

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 (4 Replies)
Discussion started by: rakeshkumar
4 Replies

5. Shell Programming and Scripting

Output Display in a perl program

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... (1 Reply)
Discussion started by: mr_manii
1 Replies

6. Programming

To display unique lines in a Program

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... (1 Reply)
Discussion started by: Teju88
1 Replies

7. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

8. Programming

program or script to display user info

I'm on a Linux machine and need a program that will display user information as follows: user name, user directory and current date & time. I think we can compile C, C++ and Perl. All help is appreciated. (4 Replies)
Discussion started by: flasun
4 Replies

9. Shell Programming and Scripting

Display a Graphic from a Unix program on a Pc – how?

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... (4 Replies)
Discussion started by: Barry Staples
4 Replies

10. UNIX for Advanced & Expert Users

Display program running on CDE via GNOME

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... (4 Replies)
Discussion started by: navinxavier
4 Replies
Login or Register to Ask a Question