Line 2: When you run the script from command line, you've to provide exactly 2 parameters. Otherwise, it'll exit.
Line 4,5: The start and end timestamp that you enter as 1st and 2nd parameters while invoking the script are converted to YYYYMMDDHHMMSS format (a single 14 digit number).
Line 7: Input file is read line by line in a while loop
Line 9: The timestamp at the beginning of each line (first 20 characters) in input file is converted to YYYYMMDDHHMMSS format.
Line 10: Date obtained in line 9 is checked with start time stamp and end time stamp found in line 4 & 5. If >= start time and <= end time, then print the line.
$# --> Refers to the number of parameters provided at command line alongside scriptname.
[ $# -ne 2 ] --> Number of parameters ($#) is not equal (-ne) to two (2)
&& --> Logical 'and' operator.
"Invalid Parameters. Exiting" --> This will be printed on screen if you don't provide exactly two parameters. Ok, my mistake.. I should've mentioned "Invalid number of parameters. Exiting."
&& --> Another logical 'and' operator
exit --> Script will exit the moment this keyword in encountered.
So, summing it up, if [ $# -ne 2 ] is true, then do echo "Invalid Parameters. Exiting.". And if that is true then do exit
This whole line is just a check to ensure that user is entering exactly two parameters alongside script name while invoking it at command line. This line is not necessary, if the user knows what exactly to enter and how much to enter.
This User Gave Thanks to balajesuri For This Post:
In the first parameter why did you give milliseconds? -- 26 Dec 2011 11:39:43,070 That was not your original requirement right? Anyway, that shouldn't matter.
Post the output of the following command:
This User Gave Thanks to balajesuri For This Post:
I recently tried the below command.
But it shows some problem..
---------- Post updated at 12:45 AM ---------- Previous update was at 12:42 AM ----------
THats correct.
But still it is throwing me an error.
I need to fetch data between two dates with timestamp.
It may occur that the starting date is not present in the file with the same timestamp.
The timestamp can vary. I need to apply the between condition.
Please help.!!
---------- Post updated at 12:54 AM ---------- Previous update was at 12:45 AM ----------
Hey..
Its working fine..
Thanks a ton..
You have been great help Mr.balajesuri..!
---------- Post updated at 01:02 AM ---------- Previous update was at 12:54 AM ----------
Can you explain me the below part of the script.
Last edited by Franklin52; 12-30-2011 at 08:58 AM..
Reason: Code tags
--> Break this into pieces. echo $x | cut -c1-20 fetches the first 20 characters of each line of log file. So, this refers to the time stamp.
--> -d switch of date command shows date as specified by the following string. Think of this as an intelligent switch of date command. For e.g., if you say date -d "1 day ago", it would display the previous days' date.
--> +%Y%m%d%H%M%S is the format in which date should be printed. Check man pages of date command.
So date -d "25 Dec 2011 10:10:10" +%Y%m%d%H%M%S would show 20111225101010. Check it out.
$dt -ge $st_date --> if value in variable dt ($dt) is greater than equal to (-ge) value in st_date ($st_date)
-a --> logical 'and' operator
$dt -le $nd_date --> if value in variable dt ($dt) is less than equal to (-le) value in nd_date ($nd_date)
&& --> another logical 'and' operator
echo $x --> print line ($x) on screen
So summing it up, if [ $dt -ge $st_date -a $dt -le $nd_date ] is true then do echo $x
Hi,
I am new to scripting. I have a log file and need to fetch specific logs and copy to another file.
A copy of the log is like this:
===============================================================
= JOB : server123#jobs1.jobstream1
= USER : andyc
= Tue 08/01/17... (3 Replies)
Hi ,
I have a file which contains 2 days logs(here it is 24 and 25)
I want to list data only for date 25 fron the file.
please suggest me how should i get this.
file content mentioned below
17-05-24 Name Succ Fail
00:00:29 ... (5 Replies)
Hi Team,
I m getting my script commands output like given below
GETA-TILL-INF;
U-UU-YRYT-NOD-6002 2015-05-14 THU 19:44:10
C2221 RETRIEVE TILL INFORMATION : COMPLD
----------------------------------------------------------------------
CONNECT_CARD_ID ... (9 Replies)
Hi Guys,
Am in need of your help one more time on my real data.
I have a file which contains more than thousand lines of data
Live data shown for 4 iterations. We have more than thousand lines of data:-
--------------------------------------------------------------------------
... (4 Replies)
Hi All,
I have a file with the below data as shown.
A|2|20120430
B|EMP|NAME|DEPT
C|12|SARC|01
C|23||ASDD|02
D|END OF FILE
I want to fetch only the records that contains C|, what is unix command to fetch this data.
Thanks (5 Replies)
Hi All,
I m new to this forum & UNix too.
currently i have a requirement which can fetch data from a logfile between two dates or timestamp.
for example:
1. data from 2012 Jun to 2012 Jul
2. data from 2012 Jun to 2012 Jul 07
3. data from 2012 Jun 16 10:20 to 2012 Jul 03 10:10
Please... (7 Replies)
I want to fetch value from a particular location from a file but in each line in the file it appears at a different position so i tried using variable with cut command but it is not working properly. The code i have written is
#!/bin/sh
cat Sri1.log |
while read d2
do
grep -w... (9 Replies)
Hi All,
There is a link from were I usually search somthing and fetch the data from.
Is there any way to automate it through a script if I mention search criteria in a note pad.
I mean the script to search the content on the notepad and resutls should be placed into another file.
... (2 Replies)
Hi,
How to fetch data from oracle database in unix shell scripting.
list=`sqlplus -s ds_user/dsuser@EMI <<EOF
set feedback off
set serveroutput on
set heading off
set pagesize 0
set tab off
select IP_ID from table
/
exit
EOF`
The output is not what i expected.I need output in... (4 Replies)
Hi All,
Can anybody tell me the command used for extracting some selected lines from
a web-page. I guess we'll have to do this using wget or Curl to achieve this....
If anbody has any idea abt it, kindly post your reply ASAP.
Thanks. (1 Reply)