Solved AWK/GAWK/TCSH guru's? Help with DATE command

Golden

000
VIP
SF Team
Local time
1:32 PM
Messages
19,301
Location
South Australia
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 Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Golden Mk. I.4
OS
Windows 10 Pro x64 ; Xubuntu x64
CPU
Intel i7 860 @ 2.80 GHz O/C'ed to 4.0GHz
Motherboard
Gigabyte P55A-UD3R Rev.1. Award BIOS F13
Memory
16GB Corsair Vengance DDR3 @ 661 MHz Dual Channel (9-9-9-24)
Graphics Card(s)
EVGA NVidia GTX 560 1024MB
Sound Card
Realtek Integrated
Monitor(s) Displays
Dual Samsung SyncMaster 2494HS
Screen Resolution
1920*1080 and 1920*1080
Hard Drives
1*Samsung 840 EVO 120GB SSD;
1*OCZ Vertex 2 60GB SSD;
2*Samsung F3 SpinPoint 1TB in RAID0;
1*Samsung F1 SpinPoint 1TB;
2*Western Digital 1TB External USB 3.0
1*Western Digital 500GB External USB 3.0
1*Seagate 500GB External USB 2.0
PSU
Thermaltake ToughPower QFan 750W
Case
Thermaltake Element S VK60001W2Z
Cooling
Corsair H60 Water Cooling, 2*230mm and 2*80mm case fans
Keyboard
Logitech G110
Mouse
Logitech MX518
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
Code:
ID,X,Y,Z,Date
1,10,10,4,3-Aug-2014
[COLOR=red]2,10,5,5,1,10-Aug-2015[/COLOR]
 

My Computer

Computer type
PC/Desktop
OS
Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
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
[COLOR="Red"]gawk -F, 'FNR != 1 {print $8}' OFS="," COL.TXT | tr -s ',' | tr -d '\r' > TEMP.JUNK[/COLOR]
[COLOR="red"]date -f TEMP.JUNK +%Y%m%d > 2.JUNK[/COLOR]
paste -d, 1.JUNK 2.JUNK > DATA.CSV
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Golden Mk. I.4
OS
Windows 10 Pro x64 ; Xubuntu x64
CPU
Intel i7 860 @ 2.80 GHz O/C'ed to 4.0GHz
Motherboard
Gigabyte P55A-UD3R Rev.1. Award BIOS F13
Memory
16GB Corsair Vengance DDR3 @ 661 MHz Dual Channel (9-9-9-24)
Graphics Card(s)
EVGA NVidia GTX 560 1024MB
Sound Card
Realtek Integrated
Monitor(s) Displays
Dual Samsung SyncMaster 2494HS
Screen Resolution
1920*1080 and 1920*1080
Hard Drives
1*Samsung 840 EVO 120GB SSD;
1*OCZ Vertex 2 60GB SSD;
2*Samsung F3 SpinPoint 1TB in RAID0;
1*Samsung F1 SpinPoint 1TB;
2*Western Digital 1TB External USB 3.0
1*Western Digital 500GB External USB 3.0
1*Seagate 500GB External USB 2.0
PSU
Thermaltake ToughPower QFan 750W
Case
Thermaltake Element S VK60001W2Z
Cooling
Corsair H60 Water Cooling, 2*230mm and 2*80mm case fans
Keyboard
Logitech G110
Mouse
Logitech MX518
Back
Top