remove the ".0" of a date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove the ".0" of a date
# 1  
Old 09-03-2012
remove the ".0" of a date

Hi,

I want to transform a txt file to make a new one. I want to remove the ".0" of the dates only (after the time, there is ".0" that I dont need.

I.e

Code:
1480.1    1.0    1.0    2012-07-08 23:38:11.0    2012-07-08 23:40:14.0

I want to transform this line to get this new one...

Code:
1480.1    1.0    1.0    2012-07-08 23:38:11    2012-07-08 23:40:14

here's the gawk I am using


Code:
gawk -F"." '$1~/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/ { print $1 substr($2,2) } ' MKT_ESTADO_CONSUMIDOR_WEB.TXT

It's ok if I don't have other "." in the line

i.e
from this line...
Code:
1479    9    0    2012-07-06 10:58:13.0    null

I get this one

Code:
1479    9    0    2012-07-06 10:58:13    null


Last edited by Scrutinizer; 09-03-2012 at 02:05 PM.. Reason: code tags
# 2  
Old 09-03-2012
Code:
perl -lnpe ' s/(\d+:\d+:\d+)\.0/$1/g;' input_file

Thanks scrutinizer for alerting on "."

Last edited by msabhi; 09-03-2012 at 01:44 PM..
This User Gave Thanks to msabhi For This Post:
# 3  
Old 09-03-2012
Or sed:
Code:
sed 's/\(..:..:..\)\.0/\1/g' infile

(the . before the 0 should be escaped)
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 4  
Old 09-03-2012
Code:
cat file_name| perl -e 's/(\d\-\d-\d\s\d:\d:\d)\.0/$1/gc'

this will give you desired output..

Last edited by Scrutinizer; 09-03-2012 at 02:05 PM.. Reason: code tags
This User Gave Thanks to replytoshishir For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

7. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

8. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

9. Shell Programming and Scripting

sed remove date ex. "Mar 25 2008"

is there any way to remove data out of a file with sed? sample file: 2 3 414 Mar 25 2008 223 312 4244 Feb 25 2008 5 312 422344 Sept 25 2008 output: 2 3 414 223 312 4244 5 312 422344 (14 Replies)
Discussion started by: katrvu
14 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question