I am required to create a CSV file reading last 200000 lines form a log file. I have to grep 3 parameters from this log file and write these parameters in the .csv file, with time stamp. This script will be setup in a cron job which will run every 10 minutes. I have written the script but it is giving me an error. Please help. I am not understanding where am i committing a mistake.
You have to use the echo command or maybe the printf command to write to a file.
The tail operation has to run in a child process. The equal sign cannot have spaces on either side of it.
I don't think RudiC's suggestion is going to work since you want separate counts of the number of lines containing each of the three strings, not a total of number of lines that contain one or more of the strings.
Since you have specified that the name of the log file to be processed is the empty string (not the name of a file), jim mcnamara's script won't work either. And, if you did provide the name of your log file, getting the last 200000 lines three times (while additions are being added to the log file by other processes) means that it will run slow and give you counts for the three strings from different sets of lines in your file. It is also dangerous to expand a variable without double quoting it if there is ANY possibility that it could contain whitespace characters, characters that are special in pathname expansions, or (as in this case) an empty string.
I would be tempted to try something more like:
This only reads the log file once and gathers individual counts for each string, but you still have to fill in the real name of the log file this script is supposed to process.
And, as always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
Last edited by Don Cragun; 10-14-2015 at 04:01 PM..
Reason: Add missing quotes.
This User Gave Thanks to Don Cragun For This Post:
But i also need to use the Code to send an SMS using the variables.
Don's script printed out the found values in the END-part. Instead of writing them directly to the csv-file you can read them into variables. Change this line:
To this:
You now have 4 variables in the shell filled with the respective values, which you can use further on in you call to curl.
Btw:
is perhaps not going to work. You should consider constructing the string differently, for clarity:
Hello Members,
I have one file which contains million of supplier code. I need to load these codes into database 1000 at a time.
Database procedure reads from an external table which is based on the unix files.
All I want to do is to read from the bigger file e.g. MAIN_FILE.txt and create... (1 Reply)
well, im a total novice of unix commands and shell scripting, i never made anything.
But yesterday in my work i was working with a lot of log files and i was wondering if there is a command for doing something like this:
i have a bunch of files with text like this:
blablabla errorcode1... (11 Replies)
Hi,
I've several files with two collumns, where first collumn can be used as index.
filename1
and filename2
how to create a file
I should start with cat all files and extract first collumn to create an index? (4 Replies)
I need a script that can do this:
A script that searches all directories and subdirectories for .html files
When a .html file is found it creates a index.html file in that folder.
It then edits the index.html file and inserts links to all of the .html files that are in that folder into the... (5 Replies)
I want to create a egrep variable from a file.
For example:
string=`cat query.txt`
cat myfile.txt | egrep "$string"
The string variable file has a list of one or multiple lines
So the end result of:
cat myfile.txt | egrep "$string"
would be:
cat myfile.txt | egrep... (2 Replies)
OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4
Looking for a script that reads the following log files that gets generated everynight between 2 - 5am
Master_App_20090717.log
Master_App1_20090717.log
Master_App2_20090717.log
Master_App3_20090717.log... (2 Replies)
Hi,
I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file.
... (11 Replies)
Hi:
I have a collection of mp3s and I need to create 1 xml file per mp3.
I have:
recording1.mp3
recording2.mp3
etc
and I want to generate this kind of files.
recording1.xml
recording2.xml
and inside each xml file I need to add a url prefix and then the filename at the end.
... (4 Replies)
why do inode indices starts from 1 unlike array indexes which starts from 0
its a question from "the design of unix operating system" of maurice j bach
id be glad if i get to know the answer quickly
:) (0 Replies)
Hi All,
Please help me in creating files through K-shell scripts.
I am having one file in this format.
OWNER.TABLE_NAME
OWNER.TABLE_NAME1
OWNER1.TABLE_NAME
OWNER1.TABLE_NAME1
I want to read the above file and create new file through k shell script.
The new file should looks like this.... (4 Replies)