Need help script to change the log file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help script to change the log file?
# 1  
Old 08-11-2009
Data Need help script to change the log file?

Hi

I have log like this :

Quote:
Date Time Object A B C D
2009-06-21 16:00 Cell=30871 0 0 0 0
2009-06-21 16:00 Cell=31402 0 0 1 0
2009-06-21 17:00 Cell=30871 0 3 0 0
2009-06-21 17:00 Cell=31402 0 0 0 0
2009-06-21 18:00 Cell=30871 0 0 0 0
2009-06-21 18:00 Cell=31402 4 0 0 0
2009-06-21 19:00 Cell=30871 0 0 0 0
2009-06-21 19:00 Cell=31402 0 0 0 0
2009-06-21 20:00 Cell=30871 0 0 0 6
2009-06-21 20:00 Cell=31402 0 0 0 0
2009-06-21 21:00 Cell=30871 0 0 0 0
2009-06-21 21:00 Cell=31402 0 4 2 0
2009-06-21 22:00 Cell=30871 0 0 0 0
2009-06-21 22:00 Cell=31402 0 0 0 0
2009-06-21 23:00 Cell=30871 0 0 0 0
2009-06-21 23:00 Cell=31402 0 0 3 0
2009-06-22 00:00 Cell=30871 0 0 0 0
2009-06-22 00:00 Cell=31402 0 0 0 0
2009-06-22 01:00 Cell=30871 0 0 0 5
2009-06-22 01:00 Cell=31402 0 0 0 0
2009-06-22 02:00 Cell=30871 0 0 0 0
2009-06-22 02:00 Cell=31402 0 0 8 0
2009-06-22 03:00 Cell=30871 0 0 0 0
2009-06-22 03:00 Cell=31402 0 0 0 0
2009-06-22 04:00 Cell=30871 0 0 0 0
2009-06-22 04:00 Cell=31402 0 0 0 0
2009-06-22 05:00 Cell=30871 0 4 0 0
2009-06-22 05:00 Cell=31402 0 0 2 0
2009-06-22 06:00 Cell=30871 0 0 0 0
2009-06-22 06:00 Cell=31402 0 0 0 0
2009-06-22 07:00 Cell=30871 0 0 0 0
2009-06-22 07:00 Cell=31402 0 2 0 0
2009-06-22 08:00 Cell=30871 0 0 0 0
2009-06-22 08:00 Cell=31402 0 0 1 0
2009-06-22 09:00 Cell=30871 0 0 0 0
2009-06-22 09:00 Cell=31402 0 0 0 0
2009-06-22 10:00 Cell=30871 0 0 0 0
2009-06-22 10:00 Cell=31402 0 0 0 0
2009-06-22 11:00 Cell=30871 0 0 0 0
2009-06-22 11:00 Cell=31402 0 0 0 0
2009-06-22 12:00 Cell=30871 0 0 0 0
2009-06-22 12:00 Cell=31402 0 0 0 0
2009-06-22 13:00 Cell=30871 0 0 0 0
2009-06-22 13:00 Cell=31402 0 0 0 0
2009-06-22 14:00 Cell=30871 0 0 0 0
2009-06-22 14:00 Cell=31402 0 0 0 0
2009-06-22 15:00 Cell=30871 0 0 0 0
2009-06-22 15:00 Cell=31402 0 0 0 0
And i want the log become like this :
Quote:
Date Time Object Type A B C D
2009-06-22 0 Cell=30871 Stream1 0 0 0 0
2009-06-22 0 Cell=31402 Stream1 0 0 1 0
2009-06-22 1 Cell=30871 Stream1 0 3 0 0
2009-06-22 1 Cell=31402 Stream1 0 0 0 0
2009-06-22 2 Cell=30871 Stream1 0 0 0 0
2009-06-22 2 Cell=31402 Stream1 4 0 0 0
2009-06-22 3 Cell=30871 Stream1 0 0 0 0
2009-06-22 3 Cell=31402 Stream1 0 0 0 0
2009-06-22 4 Cell=30871 Stream1 0 0 0 6
2009-06-22 4 Cell=31402 Stream1 0 0 0 0
2009-06-22 5 Cell=30871 Stream1 0 0 0 0
2009-06-22 5 Cell=31402 Stream1 0 4 2 0
2009-06-22 6 Cell=30871 Stream1 0 0 0 0
2009-06-22 6 Cell=31402 Stream1 0 0 0 0
2009-06-22 7 Cell=30871 Stream1 0 0 0 0
2009-06-22 7 Cell=31402 Stream1 0 0 3 0
2009-06-22 8 Cell=30871 Stream1 0 0 0 0
2009-06-22 8 Cell=31402 Stream1 0 0 0 0
2009-06-22 9 Cell=30871 Stream1 0 0 0 5
2009-06-22 9 Cell=31402 Stream1 0 0 0 0

2009-06-22 10 Cell=30871 Stream1 0 0 0 0
2009-06-22 10 Cell=31402 Stream1 0 0 8 0
2009-06-22 11 Cell=30871 Stream1 0 0 0 0
2009-06-22 11 Cell=31402 Stream1 0 0 0 0
2009-06-22 12 Cell=30871 Stream1 0 0 0 0
2009-06-22 12 Cell=31402 Stream1 0 0 0 0
2009-06-22 13 Cell=30871 Stream1 0 4 0 0
2009-06-22 13 Cell=31402 Stream1 0 0 2 0
2009-06-22 14 Cell=30871 Stream1 0 0 0 0
2009-06-22 14 Cell=31402 Stream1 0 0 0 0
2009-06-22 15 Cell=30871 Stream1 0 0 0 0
2009-06-22 15 Cell=31402 Stream1 0 2 0 0
2009-06-22 16 Cell=30871 Stream1 0 0 0 0
2009-06-22 16 Cell=31402 Stream1 0 0 1 0
2009-06-22 17 Cell=30871 Stream1 0 0 0 0
2009-06-22 17 Cell=31402 Stream1 0 0 0 0
2009-06-22 18 Cell=30871 Stream1 0 0 0 0
2009-06-22 18 Cell=31402 Stream1 0 0 0 0
2009-06-22 19 Cell=30871 Stream1 0 0 0 0
2009-06-22 19 Cell=31402 Stream1 0 0 0 0
2009-06-22 20 Cell=30871 Stream1 0 0 0 0
2009-06-22 20 Cell=31402 Stream1 0 0 0 0
2009-06-22 21 Cell=30871 Stream1 0 0 0 0
2009-06-22 21 Cell=31402 Stream1 0 0 0 0
2009-06-22 22 Cell=30871 Stream1 0 0 0 0
2009-06-22 22 Cell=31402 Stream1 0 0 0 0
2009-06-22 23 Cell=30871 Stream1 0 0 0 0
2009-06-22 23 Cell=31402 Stream1 0 0 0 0
can somebody help me??
# 2  
Old 08-11-2009
Code:
awk '{ print $1, $2, $3, (NR==1 ? "Type" : "Stream1"), $4, $5, $6, $7}' inputfile

Jean-Pierre.
# 3  
Old 08-11-2009
Hello Jean..
I think you forget about the Date, and Time also different.

Rgds,
Bow
# 4  
Old 08-11-2009
Code:
awk '
NR == 1 { print "Date Time Object Type A B C D" }
NR != 1 { print $1, int(NR/2) - 1, $3,"Stream1",$4,$5,$6,$7}
' infile > outfile

# 5  
Old 08-11-2009
Hello fpmurphy,

looks like correct..but the date column is same value..

Rgrds,
Bow
# 6  
Old 08-11-2009
A solution with gawk :
Assume new date/time = date/time + 8 hours.
Code:
awk '
BEGIN {
   h8 = 8*3600;
}
NR==1 {
   print $1,$2,$3,"Type",$4,$5,$6,$7;
   next;
}
{
  date=$1 " " $2 " " 00;
  gsub(/[\-:]/, " ", date);
  timestamp = mktime(date)+h8;
  new_date  = strftime("%Y-%m-%d", timestamp);
  new_time  = strftime("%H", timestamp)+0;
  print new_date,new_time,$3,"Stream1",$4,$5,$6,$7;
}
' inputfile

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to change file names

I have a landing directory on my unix (solaris) server, that receives the following files: MLH4301I AAOT-hhslog.610.20150805.txt MLH4301I AAOT-hhslog.611.20150805.txt MLH4301I AAOT-hhslog.612.20150805.txt MLH4301I AAOT-hhslog.613.20150805.txt and I need to add to this files the number 10000... (6 Replies)
Discussion started by: fretagi
6 Replies

2. Shell Programming and Scripting

Script to change name of a file with date

I have a file that contains todays date(for ex- test_08/30/2013) Now I want a script which will run and change the name of the file and put yesterday's date (for ex- test_08/29/2013) Please help. ---------- Post updated at 04:40 AM ---------- Previous update was at 04:31 AM ---------- I... (2 Replies)
Discussion started by: sv0081493
2 Replies

3. Shell Programming and Scripting

Script to change the file at one go on different UNIX machines

Hi Folks , I have a query that is I have a server (unix machhine) to which I login thru winscp or putty , mostly I use putty and at a particular location there is one xml(abc.xml) while which I change , let say 1) I login to first unix box hostname :- ccc74 username ... (1 Reply)
Discussion started by: tuntun27272727
1 Replies

4. Shell Programming and Scripting

Need script to change a line in file....

Hello all, I have a line of code in a file that I need to change in the /etc/sysconfig/kdump file presently the line reads: KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off" what I need to do is put a comment out the 1st line and repeat it, and... (5 Replies)
Discussion started by: gartie
5 Replies

5. Shell Programming and Scripting

shell script to change the extension of a file

I have a directory that contains several files, out of which some files are have an extra extension for example file1.new.new.new file2.new.new.new file3.new.new.new file4.new.new.new i want to write a shell script that rename all such file with only single extension like file1.new... (7 Replies)
Discussion started by: mukulverma2408
7 Replies

6. UNIX for Dummies Questions & Answers

Script to change file name

Hi, I need to write a script that changes the name of the filename. Let's say my script is named change_filename and I want to use it on a file named test1.txt. After running the script I want the filename renamed to test1_fails.txt e.g. $ ls test1.txt test2.txt test3.txt $ ... (15 Replies)
Discussion started by: millsy5
15 Replies

7. Shell Programming and Scripting

change file contents using script

Hi, Requirement:- Need to change pfile,so while executing script,it has to go to pfile location(ORACLE_HOME/dbs) and open init<SID>.ora file and change value db_name=<>. If db_name=abcd,script will change the db_name=1234 likr that.. Please help to code this (1 Reply)
Discussion started by: Sanal
1 Replies

8. Shell Programming and Scripting

Help with shell script for know when a file change it

Hi, IŽd like to know how to program a shell script for know when a file changes and based on that make another tasks all this in real time.. Thanks (2 Replies)
Discussion started by: mrios7
2 Replies

9. Shell Programming and Scripting

script to ftp file (ip change)

Hi All, If I want to ftp files from machine to local pc. But the ip must change everytime :( (due to VPN), can I write a script to easiler (no need to update ip in script)? user_name=aaa password=bbb cat ip.txt # # FTP the files # ftp -d -in 199.200.204.109 <<EOF user $user_name... (2 Replies)
Discussion started by: happyv
2 Replies

10. UNIX for Dummies Questions & Answers

script to change value in file

Hi, I have a parameter file and it contains following items $ cat TransactionParams From_Date_Parm=2005-02-25 To_Date_Parm=2005-05-25 Extract_Root_Parm=/detld1/etl/ascential/Ascential/DataStage/Projects/CTI_London/IAM Extract_Type_Parm=Transaction EDW_Database_Parm=hdw_erks... (1 Reply)
Discussion started by: gopskrish
1 Replies
Login or Register to Ask a Question