Strip time from date in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Strip time from date in a file
# 1  
Old 03-24-2009
Strip time from date in a file

I have a couple of datetime fields in a file with contents like below:

ICPBR|6373056085|1|O||||JOHN|SMITH|||H200|706|445668|||123 SMITH ST|LAGRANGE|IL|66666 |||||||N|N|N|N|N|||345676|2009.02.20-13:09:04|257655957|2009.02.20-13:09:04||||N|||||F|||||||||||

I want to strip the time off the datetime (hence converting them to date fields) like below:

ICPBR|6373056085|1|O||||JOHN|SMITH|||H200|706|445668|||123 SMITH ST|LAGRANGE|IL|66666 |||||||N|N|N|N|N|||345676|2009.02.20|257655957|2009.02.20||||N|||||F|||||||||||

Thanks,

-CB
# 2  
Old 03-24-2009
Quote:
Originally Posted by ChicagoBlues
I have a couple of datetime fields in a file with contents like below:

ICPBR|6373056085|1|O||||JOHN|SMITH|||H200|706|445668|||123 SMITH ST|LAGRANGE|IL|66666 |||||||N|N|N|N|N|||345676|2009.02.20-13:09:04|257655957|2009.02.20-13:09:04||||N|||||F|||||||||||

I want to strip the time off the datetime (hence converting them to date fields) like below:

ICPBR|6373056085|1|O||||JOHN|SMITH|||H200|706|445668|||123 SMITH ST|LAGRANGE|IL|66666 |||||||N|N|N|N|N|||345676|2009.02.20|257655957|2009.02.20||||N|||||F|||||||||||

Thanks,

-CB
try this out..
Code:
 
sed 's/\(.*\)-\([^|]*\)\(.*\)-\([^|]*\)\(.*\)/\1\3\5/g' filename

# 3  
Old 03-24-2009
Thanks Vidya,

It seems like your code left a couple of datetimestamps like:

1995.01.27-00:00:00

Maybe it has to do with the '0'.

- CB
# 4  
Old 03-24-2009
Quote:
Originally Posted by ChicagoBlues
Thanks Vidya,

It seems like your code left a couple of datetimestamps like:

1995.01.27-00:00:00

Maybe it has to do with the '0'.

- CB
sorry try this
Code:
 
sed 's/-..:..:..//g' filename

# 5  
Old 03-24-2009
That's better...

Thanks for your time and effort.

- CB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding date and time to file name

Hi All, i wanted to add date and time to the file names in the same directory so lets say a file in the directory is test.txt then after running the shell script it should be test-15-11-2010.txt. So I used the following script which works, #!/bin/bash thetime=`date +%Y-%m-%d--%H:%M:%S`... (7 Replies)
Discussion started by: cc_at_work
7 Replies

2. Shell Programming and Scripting

Strip time from CSV File?

Hi, I've been trying (and failing miserably) all morning to strip from a CSV file the time from it. Can somebody point me in the right direction on how to do this using sed or awk? The file looks like: "James","07/20/2009-14:40:11" "Steve","08/06/2006-02:34:37"... (5 Replies)
Discussion started by: nmuntz
5 Replies

3. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

4. Shell Programming and Scripting

How to extract date with time from file

Hi, I have a file where there is a date and time field, the format for it is yyyy-mm-dd hours:mins:sec the position of date field may vary anywhere in the line and it might be different and it is specified along with the variable AppTimeStamp how do i extract date and time both from the... (5 Replies)
Discussion started by: prash_b
5 Replies

5. 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

6. Shell Programming and Scripting

Extracting date-time from file.

I have the following file and need to extract date and time part for each record. Pl. could anyone provide an shell script which could be used to do it. Here is the file: /rgrdev/pdsud2/unx/agc/src/agcmst: /rgrsrc/pdspms/unx/agc/src/s.agcmst.for agcmst.for 420.20 8/4/07 18:30:53 ... (7 Replies)
Discussion started by: skumar11
7 Replies

7. Shell Programming and Scripting

Date and time log file

Hi, I wrote a small perl script in unix that searches in a file and saves some information in a separate file. Since this is a log file, I would like to have the date added to file name. I have no idea where to start. output: log_010907.txt thanks ken (8 Replies)
Discussion started by: captoro
8 Replies

8. UNIX for Dummies Questions & Answers

how do I put a date and time in a file name

I want to copy a file to another file so that the current time and date are in the file name. For example I want to copy file profit.txt to a file name in the format of profit_YYYYMMDDHHmm.txt where YYYY is year, MM is number of the month DD is the number of day of the month, HH is the hour of... (2 Replies)
Discussion started by: jhamm
2 Replies

9. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question