Script to process file from a directory and grep the required content and print


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to process file from a directory and grep the required content and print
# 15  
Old 02-08-2013
Thanks RudiC. It worked.
Can you tell me how to add the symbol "|" at result line at start and end and to run this nawk command
to a perticluar path and should read all the _Daily_Check.log file
Code:
#for file in *_Daily_Check*
#do
#        server=${file%%_*}
#        if [ -f "$file" ]
#        then
nawk 'BEGIN    {CmpAr["VerifyInterface"]=2         # some definitions
               CmpAr["CoreFileGenerated"]=3
               CmpAr["VerifyRegister"]=4
               CmpAr["VerifyComponent"]=5
               CmpAr["VerifyServiceAvailability"]=6
               split ("%-7s %36s %22s %29s %26s %29s", FMT, " ")
               red="\033[1;31m"
               grn="\033[1;32m"
               rst="\033[0m"
               clr["Failed"]=red
               clr["Passed"]=grn
              }
     function prt() {for (i=0; i<=6; i++) printf FMT[i], clr[OutAr[i]] OutAr[i] rst; printf "\n"}
     #NR == FNR     {print; next}                  # read & print header
     #($2 in CmpAr) {gsub (" ", "", $1);
      ($2 in CmpAr) {gsub (/[ \t]/,"",$1);
                    OutAr[CmpAr[$2]]=$1;          # put $1 into the right column
                    OutAr[1]=$3}                  # save server name
     FILENAME != oldfn {                          # print if old file ends
                   if (oldfn) prt(); oldfn = FILENAME}
     END              {prt()}                     # print when last file ends
 #}"$file"
  ' FS=":"  header *_Daily_Check.log
#fi

output:
Code:
|========================================================================================================|
|Server                     Interface Checks                    Process Checks              Service Check|
|                       VerifyInterface  Corefile       VerifyRegister VerifyComponent                   |
|========================================================================================================|
EEDDEEEED_DD01A                   Passed     Failed            Passed         Passed            Passed

expected output format :
Code:
|========================================================================================================|
|Server                     Interface Checks                    Process Checks              Service Check|
|                       VerifyInterface  Corefile       VerifyRegister VerifyComponent                   |
|========================================================================================================|
|EEDDEEEED_DD01A                   Passed     Failed            Passed         Passed            Passed  |
|EEDDED_DD01B                   Passed     Failed            Passed         Passed            Passed     |
|EEDDEAA_EEED_DD01C                   Passed     Failed            Passed         Passed         Passed  |
|========================================================================================================|

# 16  
Old 02-08-2013
I'm not sure I understand. You said you wanted to exclude the header file and run the awk program on one log file at a time within a shell script. OK, fine with me. Now you say, you nevertheless want to run it on a directory full of files ? ... But OK, that's up to you.
For | symbols at the begin and end of each line, modify the prt function: put a printf "|"; in front of the for loop, and modify the last to printf "|\n".
To run it on a number of files in a certain path, modify the file list: awk '...' /a/certain/path/*_Daily_Check.log

BTW, you commented out the header printing in the program, but left "header" in the file list...
AND, for server names that long, modify the split (..., FMT, ...) line, increasing the %-7s at the expense of the following %36s.
This User Gave Thanks to RudiC For This Post:
# 17  
Old 02-12-2013
Thanks RudiC. It was very helpful.

thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. Shell Programming and Scripting

Script to search every file in a directory and print last few lines

Hi everyone, I need to write a script to search a directory, output the name of a file to an ouput file and print the last few lines of the files to the output file such that I would have something like this: FILE1: LINE LINE LINE FILE2: LINE LINE LINE FILE3: LINE LINE LINE... (2 Replies)
Discussion started by: mojoman
2 Replies

3. Shell Programming and Scripting

Help required to Print Single quote into a file

Hi, I need help in printing string enclosed with single quotes to a file. I am trying to write a shell script which when run will create another script below is the script logic. cat create_script.sh echo '#!/bin/sh' > append_flname.sh echo 'for FILE in $*' >> append_flname.sh echo... (6 Replies)
Discussion started by: imrandec85
6 Replies

4. Shell Programming and Scripting

How to Modify a file content in UNIX and sort for only required fields ?

I have the below contents in a file after making the below curl call curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test "state" : "Disconnected",, "Rno" : "5554f1d2" "state" : "Disconnected",, "Rno" : "10587563" "state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 Replies

5. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

6. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

7. Shell Programming and Scripting

Goto each directory and subdirectories and grep the required pattern

Hi All, I need your help in finding pattern from files present in different directories. I need to search for a pattern "xyz" from "*.txt" files which are present in different levels of directories as shown. example ------- dir1/subdir1/file.txt dir2/subdir2/subsubdir2/file.txt... (5 Replies)
Discussion started by: imas
5 Replies

8. UNIX for Dummies Questions & Answers

Print the content of a directory in jpg file

Is there any possible way to print the contents of a directory to a .jpg file? I have a list of thumbnails (e-books) which I want to share (+500) but I don't know how to make this. I would appreciate a lot any comments regarding this issue. (4 Replies)
Discussion started by: agasamapetilon
4 Replies

9. Shell Programming and Scripting

shell script to search content of file with timestamps in the directory

hello, i want to make a script to search the file contents in my home directory by a given date and output me the line that has the date... (10 Replies)
Discussion started by: psychobeauty
10 Replies
Login or Register to Ask a Question