UNIX shell script to format output report


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX shell script to format output report
# 1  
Old 09-08-2014
UNIX shell script to format output report

i am new to unix shell scripting, could someone please help me. i was asked to develop a unix script and requirement of the script is as follows:

1. In source directory, if any new files are being dropped by external system then an email should be sent out with a message saying "files are available for further processing".
2. Generate for a string in each *.XML file and get the count of next to each XML file name
format should be:
Code:
XML file name | string occurrence | count (occurrence of string in XML file)

3. if count of string occurrence in XML file is less than 7, should be moved to rejected directory.
4. if count of string occurrence in XML file is equal to 7, should be moved to processed directory.
5. after files are being moved to processed directory, files should be inserted in MYSQL database.
6.final validation, count of XML file name and no.of records which are inserted in MYSQL database should be matched.

Last edited by Don Cragun; 09-08-2014 at 10:04 PM.. Reason: Fix tags.
# 2  
Old 09-08-2014
Some questions that might help matters along...

1) What mail utilities do you have available to you on the server in question?
2) Is there a single, particular string that you're trying to search for in the XML files? For example, maybe you are always looking for "BINGO", and so could use something like:
$ grep -c BINGO <file>
3) Do you have credentials and table information for the DB?

So, a quick and naive stab at it that might give a starting point for 2-4:

Code:
for file in /dir/ect/ory/*.xml
do
   stringcount=`grep -c BINGO $file`
   if [ "$stringcount" -lt 7 ]
   then
      mv $file /rej/ect/ed
   else
      mv $file /pro/ces/sed
   fi
done

There's no point to attempting #1 without more information about what's available on the server for sending emails. Similarly, we'd need to know about the MySQL DB in order to know about submissions to that.
# 3  
Old 09-08-2014
thanks treeslouth,
need an output in the following format, could you please help me...

example:
Code:
XML File name | list of matching string | count
abc.xml          | abc file                       | 2
                      | xyz file                       |
xyz.xml           | ccc file                       | 1

Moderator's Comments:
Mod Comment CODE tags are crucial to make column alignment visible.

Last edited by Don Cragun; 09-08-2014 at 10:06 PM.. Reason: Add CODE tags.
# 4  
Old 09-10-2014
Quote:
Originally Posted by crefi1545
thanks treeslouth,
need an output in the following format, could you please help me...

example:
Code:
XML File name | list of matching string | count
abc.xml          | abc file                       | 2
                      | xyz file                       |
xyz.xml           | ccc file                       | 1

Moderator's Comments:
Mod Comment CODE tags are crucial to make column alignment visible.
So you mention "list of matching string". Are there multiple strings that you're counting? For example, do you want to know how many times, in total, either "foo" or "bar" appear in an XML file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python or Shell script to Grep strings from input file and output in csv format

Hi Experts, I am writing a python script to grep string from file and display output in csv file as in attached screenshot https://drive.google.com/file/d/1gfUUdfmQma33tz65NskThYDhkZUGQO0H/view Input file(result_EPFT_config_device) Below is the python script i have prepared as of... (1 Reply)
Discussion started by: as7951
1 Replies

2. Shell Programming and Scripting

Shell output format like table

Hi, OS: Redhat 7.5 shell: Bash Wrote below script to login into oracle via shell script and trying to reset locked account..It works as expected. But I need specific output << EOF should go to target terminal not all out put running below script from ansible command line.. #!/bin/bash... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

UNIX script email to outlook report format

I have a ksh script that emails a report to outlook from a Unix Solaris. On server the report formatted perfectly. However, the email version the format is not. On the server report looks like this: TN Region Old SPiAD Server Order/Req Local Status NAAC Status Request Date New... (1 Reply)
Discussion started by: mrn6430
1 Replies

4. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

6. UNIX for Dummies Questions & Answers

UNIX command output format

how can I get the df -h command output into excel format or csv file. df -k | tr -s " " | sed 's/ /, /g' | sed '1 s/, / /g' | column -t df -h | column -t I have tried as above but the format is not right. I'm not able to load the format into a excel or a table. ... (2 Replies)
Discussion started by: anita81
2 Replies

7. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

8. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

9. Shell Programming and Scripting

Help with Output Redirection of a Unix Shell Script

Hi Guys, I have a script for which the stdout and stderr should be redirected to a log file, they should not be printed on the screen. Could you please let me know the procedure to redirect the output of the script to a log file. Thanks in advance. --- Aditya (5 Replies)
Discussion started by: chaditya
5 Replies

10. UNIX for Advanced & Expert Users

Unix Shell Script with output to CSV File

Hi, I have a unix shell script that is outputting results from an SQL query to a *.csv file, using utl_file.put_line. The resulting file is then sent out via e-mail as a mail attachment. The issue I have is that when the mailed attachment is opened in Excel the first column is shown as... (1 Reply)
Discussion started by: heather.morton@
1 Replies
Login or Register to Ask a Question