Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: AWK/GAWK/TCSH guru's? Help with DATE command

19 Aug 2015   #1
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 
AWK/GAWK/TCSH guru's? Help with DATE command

Are there any GAWK/TCSH guru's about that can give me a hand with this?

Imagine an ASCII format file with 5 columns of data:

Code:
ID,X,Y,Z,Date
1,10,10,4,3-Aug-2014
2,10,5,5,1,10-Aug-2015
.
.
.
.
I'm trying to change the date format in the last column such that 10-Aug-2015 is represented as 20150810. On a TCSH command line, I can do this by using the date command as follows:

Code:
date -d "10-Aug-2015" +%Y%m%d
The problem is I have several hundred files and each can have up to 100,000 lines. Thus, I need a mechanism to parse column 5 through the date command, such that each instance of the date is formatted as described. I only have the TCSH and GAWK (at a push SED) tools available to solve this, so my plan was to write a TCSH script referencing GAWK to do this.

I have tried piping the date command through a gawk print statement, but I can't quite work out how to read $5 into the date command. I'd had a look on several UNIX sites, but have yet to find a solution.

Can anyone help?

Thanks.
My System SpecsSystem Spec
20 Aug 2015   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Is it not an option to import all these files to a Windows machine and use PowerShell instead, then place them back?

Btw, line 3 in your example csv file has 6 columns
Quote   Quote: Originally Posted by Golden View Post
Code:
ID,X,Y,Z,Date
1,10,10,4,3-Aug-2014
2,10,5,5,1,10-Aug-2015
My System SpecsSystem Spec
20 Aug 2015   #3
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

Thanks for the reply. I wanted to try and keep everything in TCSH since I have other things that are scripted to run on the data, and it makes things easy to manage..

Anyway, I landed on a solution. Its clunky and dirty, but it works

Code:
gawk -F, 'FNR != 1 {print $1","$3","$4","$5}' OFS="," COL.TXT | tr -s ',' | tr -d '\r' > 1.JUNK
gawk -F, 'FNR != 1 {print $8}' OFS="," COL.TXT | tr -s ',' | tr -d '\r' > TEMP.JUNK
date -f TEMP.JUNK +%Y%m%d > 2.JUNK
paste -d, 1.JUNK 2.JUNK > DATA.CSV
My System SpecsSystem Spec
.

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar help and support threads
Thread Forum
File search (by date range) displays incorrect Mod Date in results
Searching for files modified in a specified date range (of the past 3 days) gets a search result list titled "date modified", and with the column heading "Date Modified" but the date listed against a file modified today is wrong. The date displayed matches the file creation date & is within the...
General Discussion
Date format using space as date separator rather than forward slash!
Hi all, I'm new to Windows 7 (Home Premium 32-bit) and I just can't figure out what's going on here! Basically I want my short date format to be dd/mm/yyyy (UK format) e.g. 05/11/2010, but when I key a date into Excel 2002 it is appearing as 05 11 2010. In Control Panel I have the short date...
General Discussion
Need some Help guru's. Please.
Hey guys, I brought in a windows 7 disc to upgrade a coworkers dell laptop from vista to windows 7 ultimate. The install itself went fine, but after the 1st restart, the pc just does looping restarts and can't enter into the OS. When i boot from the win7 cd, it recognizes that windows 7 is the...
Installation & Setup


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 06:11.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App