Filter date and time form a file using sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter date and time form a file using sed command
# 8  
Old 04-20-2011
whatever @michaelrozar17 has posted is working for me.
Which is your OS? Solaris? If so, use /usr/xpg4/bin/awk

regards,
Ahamed
# 9  
Old 04-20-2011
Hey @michaelrozar17 thanks, Its working, but there is another issue. If the file is like this it doesnt work

input file:

abcd
sadfgfg
on Tue Apr 19 00:48:29 2011
sghjkll
on Wed Mar 20 01:48:29 2011
aaabb223344
anhs asadh
on Wed Mar 20 01:48:29 2011
# 10  
Old 04-20-2011
Quote:
Originally Posted by vineet.dhingra
Hey @michaelrozar17 thanks, Its working, but there is another issue. If the file is like this it doesnt work

input file:

abcd
sadfgfg
on Tue Apr 19 00:48:29 2011
sghjkll
on Wed Mar 20 01:48:29 2011
aaabb223344
anhs asadh
on Wed Mar 20 01:48:29 2011
Your fault, please provide better examples of your input file when asking questions.

Thank you.
# 11  
Old 04-20-2011
Hey @Franklin52 will keep this in mind from next time. please help me with this..
# 12  
Old 04-20-2011
Assuming the timestamp in the file has the word on before it
Code:
sed '/.. ... ... [0-9][0-9]/s/\(.* *on\) .*/\1/' inputfile > outfile

This User Gave Thanks to michaelrozar17 For This Post:
# 13  
Old 04-20-2011
Hey @michaelrozar17 can it be dependent on the time ie(00:12:17) as it will solve anoher purpose to me. may be somewhat like this....

sed '/... ... [0-9][0-9] [0-9][0-9]/:[0-9][0-9]/:[0-9][0-9]/s/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Including Hash / in sed command filter

Hello All, I want to print data in between two lines in a file sample.txt through more or cat command on the screen. For that I am using below sed command to give the BEGIN and END text. Content of sample.txt server01:~ # cat /proc/mdstat Hello this is a text message 1 Hello this is a... (5 Replies)
Discussion started by: Xtreme
5 Replies

2. Linux

Filter log file contents between date

Hi, Could you please provide me command to filter contents between date in a log file? Say for example, in a log file I want to capture contents between date May 01 from 5am to 9 am. OS -- Linux Regards, Maddy (1 Reply)
Discussion started by: Maddy123
1 Replies

3. Shell Programming and Scripting

History of all the users in single file with command , date . time , ip and user

HTML Code: archive_history() { HISTORYOLD=${HISTFILE}.archive CURTIME=`date` CURTTY=`tty` IP=$(echo $SSH_CLIENT | awk '{print $1}') if ; then echo "#-${HOSTNAME}-- ${CURBASHDATE} - ${CURTIME} ($CURTTY) ${USER} ${IP}----" >> $HISTORYOLD history... (0 Replies)
Discussion started by: rehantayyab82
0 Replies

4. Shell Programming and Scripting

History of all the users in single file with command , date . time , ip and user

HTML Code archive_history() { HISTORYOLD=${HISTFILE}.archive CURTIME=`date` CURTTY=`tty` IP=$(echo $SSH_CLIENT | awk '{print $1}') if ; then echo "#-${HOSTNAME}-- ${CURBASHDATE} - ${CURTIME} ($CURTTY) ${USER} ${IP}----" >> $HISTORYOLD history... (2 Replies)
Discussion started by: rehantayyab82
2 Replies

5. Shell Programming and Scripting

Problem with filter data using sed command

Hi, I am using the following command(sed) to get the key/value pair from the string String="{ "test":"test message", "testmessage":"subscription is active, charge successfully} " }" status=$( echo $String | sed -e 's/^.*\("testmessage":*\).*$/\1/') echo $status i am getting this... (2 Replies)
Discussion started by: nanthagopal
2 Replies

6. Shell Programming and Scripting

how to filter file for specific date

Hi My OS is solaris 64 bit 10, I have many files in a logs directory where we recive 40-50 logs every day. i have last 20 days file present in this directory. I want to move each day file to a particulaar directory whose name is appended with the date of file. eg Code: 1.txt file... (1 Reply)
Discussion started by: guddu_12
1 Replies

7. Shell Programming and Scripting

find command to filter specific type of files older than certain date.

Hi I need to find the list of files in a directory and to do some specific operations based on the type of files. suppose in a directory am having .dat , .log, .err, .rej file types. i need to filter out .dat and .log only which are older than six months. i used the below query but the... (2 Replies)
Discussion started by: msathees
2 Replies

8. Shell Programming and Scripting

extract last modified time of file in form of YYYYMMDD

Hi All, I want to extract last modified, seen in ls -l command, of a file and then convert it into "YYYYMMDD" format. Any help regarding would be helpful Thanks in advance... (3 Replies)
Discussion started by: itsme_maverick
3 Replies

9. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

10. Shell Programming and Scripting

Help needed - Replacing all date & time occurrences in a file with a string using Sed

Hi, I am new to using Sed. I have a file containg lines like the following: INFORM----Test.pc:168:10/11/05 12:34:26 > some text goes here.. TRACE-----Test.pc:197:10/11/05 12:34:26 > some text goes here.. My requirement is to replace 10/11/05 12:34:26 with a string <RUNDATE> (including <... (4 Replies)
Discussion started by: Hema_M
4 Replies
Login or Register to Ask a Question