BASH script outputting strange file formats


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH script outputting strange file formats
# 1  
Old 08-17-2011
BASH script outputting strange file formats

Hi

I am very new to using BASH, but I have a problem with a piece of script that I have been working on. Basically the script goes through a mailbox file looking at particular aspects of the file, for example how many spamwords there are email address etc. It does this pretty well except for an error on the command line telling me about some kind of symbol not being a valid identifiereclare, which I dont know what it means but it still kind of works. It displays the results then from the mailbox file about how many email address etc are present in to a html file which the script creates with a predefined filename for the html file, however when it does this it creates the html file with the filename.html and a fullstop on the end of that. So it looks like "filename.html.". Obvioulsy this doesnt open but when you remove the fullstop from the end it works. Has anyone got any idea what is going on, I have tried looking through the code but I cant see anything wrong and I have tried looking on forums and websites but there is no mention of this.
Also I am using an emulator, working on the BASH file on windows using "cygwin". I can show what I have so far, just wondering first if anyone else has experianced this problem.

Thanks to all who help.
# 2  
Old 08-17-2011
No magic. There is a typo or a bug somewhere in the script.
# 3  
Old 08-17-2011
Could I post the code I have to let you see, as I cant find what the problem would be.
# 4  
Old 08-17-2011
Why not? Only remove confidential information and use code tags.
# 5  
Old 08-17-2011
Here is what I have so far,
Code:
#/bin/bash
declare emailno viagra sex lolita cialis million 
emailno=`egrep -c '^Subject' sussmail.mbx`
viagra=`egrep -c -i 'v..gr.' sussmail.mbx`
sex=`egrep -c -i 's.x' sussmail.mbx`
lolita=`egrep -c -i 'l.l.t.' sussmail.mbx`
cialis=`egrep -c -i 'c..l.s' sussmail.mbx`
million=`egrep -c -i 'm.ll..n' sussmail.mbx`
echo "This file contains"
echo $emailno
echo "email messages"
echo "This file contains"
echo $viagra
echo "counts of the word viagra"
echo "This file contains"
echo $sex
echo "counts of the word sex"
echo "This file contains"
echo $lolita
echo "counts of the word lolita"
echo "This file contains"
echo $cialis
echo "counts of the word cialis"
echo "This file contains"
echo $million
echo "counts of the word million"
echo "<html>" >spamstats.html
echo "<head><title>Analysis of sussmail.mbx file</title></head>" >>spamstats.html
echo "<body>" >>spamstats.html
echo "<h1>This is an analysis of the sussmail.mbx file, the following is the result found from the file.</h1>" >>spamstats.html
echo "<h3>Total number of email messages contained in Mailbox file</h3>"$emailno >>spamstats.html
echo "<h3>Total counts of the word Viagra, however spelt</h3>"$viagra >>spamstats.html
echo "<h3>Total counts of the word Sex however spelt</h3>"$sex >>spamstats.html
echo "<h3>Total counts of the word Lolita however spelt</h3>"$lolita >>spamstats.html
echo "<h3>Total counts of the word Cialis however spelt</h3>"$cialis >>spamstats.html
echo "<h3>Total counts of the word Million however spelt</h3>"$million >>spamstats.html
echo "</body>" >>spamstats.html
echo "</html>" >>spamstats.html

# 6  
Old 08-17-2011
Ok. Maybe sometimes there is magic. Smilie
On Linux box this script works without any problems. And yes it's simple and there are not any typos.
As you can see I don't believe in magic so my fantasy is very limited. I couldn't suggest what may happen. :-(
---
Some crazy thought - may be you ran your script from "cmd" window with cmd as shell? Or from GUI?
# 7  
Old 08-17-2011
Haha ok thanks anywaySmilie. Is it possible then that it is something to do with cygwin?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ubuntu 16 Bash strange output

Hello, I work in Ubuntu 16.04, I am new to Bash and something is wrong with my script, please help. I have a few hundreds of subjects data (like subj003.nii.gz, subj012.nii.gz etc. up to subj567.nii.gz) in a directory /usr/afewmoredirectories/subjects. I may run for each subject a command... (5 Replies)
Discussion started by: lim-lim
5 Replies

2. Shell Programming and Scripting

Need to check the file formats

Hi, I want to check the incoming files whether the file is Mac file or dos/windows file in unix shell script. Sometimes client is posting Mac file and sometimes it is dos file. Could you please help me how to determine/check whether the file is Mac or dos. Help in advance Thanks (4 Replies)
Discussion started by: lkeswar
4 Replies

3. Shell Programming and Scripting

Bash string variable outputting incorrectly

Hello All, I am learning BASH scripting and I would appreciate any help with a small problem I am having... I am writing a script that builds a simple hosts file for DNS reasons related to a piece of software called netdb by parsing another application's config files for IP's and their... (4 Replies)
Discussion started by: Wesley545
4 Replies

4. UNIX for Dummies Questions & Answers

outputting set -x to file

I need to enable set -x in my croned script as at times the script is not returning all data that it should be. This only happens intermittently and as such I would like a means of being able to check what goes wrong. My question is how to output the debug of set -x to file? (1 Reply)
Discussion started by: rob171171
1 Replies

5. Shell Programming and Scripting

ksh script to create a generic csv file from different source formats

Hi all, I have a requirement to create a "superset" file out of a number of different sources with some different and some same columns. We intend to have a manually updateable SuperSetCols.csv which would look like "ColA","ColB","ColC","ColD","ColE","ColF","ColG" so someday we may add... (3 Replies)
Discussion started by: Leedor
3 Replies

6. Shell Programming and Scripting

Strange error in bash script

Howdy all, I have a scritp that does a sqldump. But for some goofy reason, a certain part of it behaves uber strange. It does a daily dump of my sql, according to parameters I enter in hardcode. The script is: #!/bin/bash APP_NAME="app_com_site" wikiname="wiki_com_site" ... (8 Replies)
Discussion started by: saariko
8 Replies

7. Shell Programming and Scripting

Script Assistance - Outputting to file with Awk

I'm trying to take a list of domains, find out the MX resolve it to IP then find out what the NS is and output the contents to a new file. The only problem i'm having is when checking the Ip or host of the MX i can only get it to print the column with the MX record and the results of the host... (1 Reply)
Discussion started by: spartan22
1 Replies

8. Shell Programming and Scripting

simple count script outputting mass errors

script outputting cant find anything wrong with the script either... : #!/bin/sh #count execution script time=0 while do if then time=`expr $time + 1` if then echo "The current tick is 100" fi fi (2 Replies)
Discussion started by: aspect_p
2 Replies

9. Shell Programming and Scripting

expr not outputting properly.. bsd sh script

When i run sh -x test.sh, expr outputs x=expr $x + 1 instead of doing the arithmetic.. been working on this overnight.. and its being a pain in the arse if you ask me.. :confused::confused: #!/bin/sh #script for downloading numerical filenames chap=1 p=1 count=0 x=1 while do if ... (2 Replies)
Discussion started by: aspect_p
2 Replies
Login or Register to Ask a Question