I have a script which has to be scheduled to run 3 times a day.
My script picks the required fields from logfile and stores the data in a.csv file.
Sample data.
my logfile contain:
So the output of first execution will be stored in a.csv file:
Before second execution of script now logfile contain:
So my output should be appended to a.csv file keeping old data and appending new data to it with some line and time in between as below:
I want my output like this.
---------- Post updated at 05:55 AM ---------- Previous update was at 05:48 AM ----------
Moderator's Comments:
I don't know where you copy and paste your output from, but could you please stop using it! Every single line contains font and size tags, and it's a nightmare to edit. Thank you.
Last edited by Scott; 09-05-2010 at 08:09 AM..
Reason: Code tags, please...
Not sure what you are trying to do with all those awk invocations in your shell script, but if you want to pick up the delta from an incrementing logfile then you could do something like this:
The diff command displays the delta records in the logfile with a preceding "<"; you filter those and redirect to your csvfile with the date on top.
tyler_durden
In case you want to embellish the delta header like so -
then you'll have to figure out the last "phase" number first, increment it and then append it followed by the date and delta records.
This awk one-liner returns 2 if a phase isn't present in the csvfile, otherwise it returns the incremented phase number.
So you could assign it to a shell variable and pass that to your awk script like so -
And finally, if the logfile doesn't exist then you simply copy csvfile to logfile. (This is the simplest part, and you should be able to do this on your own.)
For all other cases, the script posted above should work.
HTH,
tyler_durden
Last edited by durden_tyler; 09-05-2010 at 03:40 PM..
I have to append the new data received from logfile to csvfile
Actually my logfile contain a file,so using awk command I am picking the required data and storing in csvfile.
Logfile is not the same as csvfile.
csvfile contain some fields that are reuired.
So I cant differentiate logfile and csvfile.
As below mentioned in my script.
Actually my logfile contain a file,so using awk command I am picking the required data and storing in csvfile.
Logfile is not the same as csvfile.
csvfile contain some fields that are reuired.
So I cant differentiate logfile and csvfile.
As below mentioned in my script.
I want append data to a.csvfile
Sorry, the following line in my post:
should read:
For the data you've provided, I believe diff should work.
If the data you've provided doesn't match your actual data (or the one that your script works on), then modify your example and show us exactly what you are trying to pick up from your logfile.
Finally, csvfile in my post should be considered a.csv (which was "a csv file" in your first post).
Experts,
I am writing a script and able to write only small piece of code and not able to collect logic to complete this task.
In input file have to look for name like like this (BGL_HSR_901_1AG_A_CR9KTR10) before sh iss neors. Record this (BGL_HSR_901_1AG_A_CR9KTR10) in csv file
Now have to... (0 Replies)
I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file
Command that Ive been using... (6 Replies)
Hi, I am newbie in shell script.
I need your help to solve my problem.
Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file.
File1:
SourceFile,DateTimeOriginal
/home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Hi All
I will run the same script every day in corn and output should go to same CSV file but in different row with dates on it. Below is my example in attached format.
Script i am using to collect switch port online
DATE=`date '+%d-%m-%y'`
for f in `cat... (1 Reply)
Hi ,
i have two log files, i need to combine this as a one log file.
i need to do this by SED ,
test1.log
sadadadaadfsaf
test2.log
adadadadadada
i need this in a single file from test 1 to test2.log
test2.log(expected result)
adadadadadada (7 Replies)
I have an issue where I need to append a value at the last of the csv, I have created a shell script and it is appending the columns at the last but it is appending at all lines, and my requirement is specific to just append at the 1st line.
Have a look and suggest, (7 Replies)
Hi,
I create a csv file and the output looks like below
Arun,E001
Sathish,E003
Now i need to include the below header and the output should like below
Name,Number
Arun,E001
Sathish,E003
Please guide me.
Thanks (4 Replies)
hai..i am new to unix..and i've currently learn shell script..
i have this small problem where i would like to save every data from log file into user directory if the data is equal to the name of the user..
i manage to do that with below script..
i would like to ask if there is any solutions so... (1 Reply)
i want to develop a script newdata that writes new data to a file called items
the file items has the following headings columns separated by tabs:
channel date time programe
if i type executable file newdata on the command line with parameters, it should append it to the items files
the... (1 Reply)
Hi ,
Can some one help in appending the file name to all the rows in .csv files the current work is like this.
This is adding a new line for file name,
I need to append file name to all lines in .csv
for i in `ls $filename*.csv`
do
echo "$i" > ./tmpfile
cat "$i" >> ./tmpfile
mv... (3 Replies)