Sponsored Content
Operating Systems Linux How do I format a Date field of a .CSV file with multiple commas in a string field? Post 302864365 by blackrageous on Wednesday 16th of October 2013 01:27:16 PM
Old 10-16-2013
If input is in file x.x, then....
Code:
cat x.x | sed -e 's/,"/\|/g' | cut -f9 -d\| | tr -d \" | awk -F\- 'BEGIN{MON["JAN"] = "01"; MON["FEB"] = "02"; MON["MAR"] = "03"; MON["APR"] = "04"; MON["MAY"] = "05"; MON["JUN"] = "06"; MON["JUL"] = "07"; MON["AUG"] = "08"; MON["SEP"] = "09"; MON["OCT"] = "10"; MON["NOV"] = "11"; MON["DEC"] = "12"} { printf("20%s/%s/%s\n",$3,MON[$2],$1) }'

or create file x.awk with
Code:
BEGIN{MON["JAN"] = "01"; MON["FEB"] = "02"; MON["MAR"] = "03"; MON["APR"] = "04"; MON["MAY"] = "05"; MON["JUN"] = "06"; MON["JUL"] = "07"; MON["AUG"] = "08"; MON["SEP"] = "09"; MON[
"OCT"] = "10"; MON["NOV"] = "11"; MON["DEC"] = "12"} 
{ printf("20%s/%s/%s\n",$3,MON[$2],$1) }

and execute like
Code:
cat x.x | sed -e 's/,"/\|/g' | cut -f9 -d\| | tr -d \" | awk -F\- -fx.awk

---------- Post updated at 12:27 PM ---------- Previous update was at 11:47 AM ----------

Got the order of args in printf wrong, this should work...
Code:
cat x.x | sed -e 's/,"/\|/g' | cut -f9 -d\| | tr -d \" | awk -F\-  'BEGIN{MON["JAN"] = "01"; MON["FEB"] = "02"; MON["MAR"] = "03";  MON["APR"] = "04"; MON["MAY"] = "05"; MON["JUN"] = "06"; MON["JUL"] =  "07"; MON["AUG"] = "08"; MON["SEP"] = "09"; MON["OCT"] = "10";  MON["NOV"] = "11"; MON["DEC"] = "12"} {  printf("20%s/%s/%s\n",$1,MON[$2],$3) }'

This User Gave Thanks to blackrageous For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

change field 2 date format

from this input WEBELSOLAR,29122009,1:1 WIPRO,15062010,2:3 ZANDUREALT,18012007,1:3 i want output as WEBELSOLAR,20091229,1:1 WIPRO,20100615,2:3 ZANDUREALT,20070118,1:3 basically input is in ddmmyyyy format and i was to convert it to yyyymmdd format (1 Reply)
Discussion started by: manishma71
1 Replies

2. Shell Programming and Scripting

csv file field needs to be changed current system date with awk

HI, I have csv file with records as shown below. 4102,Bangalore,G10,21,08/17/2011 09:28:33:188,99,08/17/2011 09:27:33:881,08/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

3. Shell Programming and Scripting

Replace field with commas with field without commas

Hey guys, I have the following text: 1,2,3,4,5,6,'NULL','when',NULL,1,2,0,'NULL' 1,2,3,4,5,6,'NULL','what','NULL',1,2,0,1 I need the same text with the word NULL without commas u know something like this: 1,2,3,4,5,6,NULL,'when',NULL,1,2,0,NULL 1,2,3,4,5,6,NULL,'what','NULL',1,2,0,1 ... (1 Reply)
Discussion started by: lmyk72
1 Replies

4. Shell Programming and Scripting

CSV with commas in field values, remove duplicates, cut columns

Hi Description of input file I have: ------------------------- 1) CSV with double quotes for string fields. 2) Some string fields have Comma as part of field value. 3) Have Duplicate lines 4) Have 200 columns/fields 5) File size is more than 10GB Description of output file I need:... (4 Replies)
Discussion started by: krishnix
4 Replies

5. Shell Programming and Scripting

Field validations in multiple files CSV

Hi, I am regular reader of this forum. My advanced thanks to everyone. Below given are the sample files INDATA (Main data) Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. Fild1Çfld2Çfld3….. . . N records (140000) eg GRPDATA (Reference file) (2 Replies)
Discussion started by: hyperion.krish
2 Replies

6. Shell Programming and Scripting

awk - CSV file - field with single or multiple spaces

Hi, In a csv file, I want to select records where first column has zero or multiple spaces. Eg: abc.csv ,123,a ,22,b ,11,c a,11,d So output should be: ,123,a ,22,b ,11,c Please advise (5 Replies)
Discussion started by: vegasluxor
5 Replies

7. Shell Programming and Scripting

Print particular string in a field of csv file

Hi, all I need your help and suggestions. I want to print particular strings in a field of a csv file and show them in terminal. Here is an example of the csv file. SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw... (9 Replies)
Discussion started by: refrain
9 Replies

8. Shell Programming and Scripting

Print particular string in a field of csv file - part 2

Hi, all I need your help and suggestions. I want to print particular strings in a field of a csv file and show them in terminal. Here is an example of the csv file. SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw... (7 Replies)
Discussion started by: refrain
7 Replies

9. Shell Programming and Scripting

CSV Split field to check multiple codes

Hello, For work i am trying to generate a combined csv file excisting out of 2 other csv files. The problem i am facing is that the first field on both files have multiple values in there which arent always the same. This first field is also the joining part. The layout of the files is as... (16 Replies)
Discussion started by: SDohmen
16 Replies

10. UNIX for Advanced & Expert Users

Help changing date format in the nth field

Hi, I have two (2) things that I want to do. First is to change the date format that is in the nth field from MM/DD/YY to YY/MM/DD. Preferably, I wish I know how to make it a 4-digit year but I don't. Problem is I can only assume it is a 20 century Second is somehow know how to figure out... (1 Reply)
Discussion started by: newbie_01
1 Replies
cupsd-logs(5)							    Apple Inc.							     cupsd-logs(5)

NAME
cupsd-logs - cupsd log files (access_log, error_log, and page_log) DESCRIPTION
cupsd(8) normally maintains three log files: access_log to track requests that are submitted to the scheduler, error_log to track progress and errors, and page_log to track pages that are printed. Configuration directives in cupsd.conf(5) and cups-files.conf(5) control what information is logged and where it is stored. ACCESS LOG FILE FORMAT The access_log file lists each HTTP resource that is accessed by a web browser or client. Each line is in an extended version of the so- called "Common Log Format" used by many web servers and web reporting tools: host group user date-time "method resource version" status bytes ipp-operation ipp-status For example: 10.0.1.2 - - [01/Dec/2005:21:50:28 +0000] "POST / HTTP/1.1" 200 317 CUPS-Get-Printers successful-ok-ignored-or-substituted-attributes localhost - - [01/Dec/2005:21:50:32 +0000] "GET /admin HTTP/1.1" 200 0 - - localhost - - [01/Dec/2005:21:50:32 +0000] "POST / HTTP/1.1" 200 157 CUPS-Get-Printers successful-ok-ignored-or-substituted-attributes localhost - - [01/Dec/2005:21:50:32 +0000] "POST / HTTP/1.1" 200 1411 CUPS-Get-Devices - localhost - - [01/Dec/2005:21:50:32 +0000] "GET /admin HTTP/1.1" 200 6667 - - The host field will normally only be an IP address unless you have enabled the HostNameLookups directive in the cupsd.conf file or if the IP address corresponds to your local machine. The group field always contains "-". The user field is the authenticated username of the requesting user. If no username and password is supplied for the request then this field contains "-". The date-time field is the date and time of the request in local time and is in the format "[DD/MON/YYYY:HH:MM:SS +ZZZZ]". The method field is the HTTP method used: "GET", "HEAD", "OPTIONS", "POST", or "PUT". "GET" requests are used to get files from the server, both for the web interface and to get configuration and log files. "HEAD" requests are used to get information about a resource prior to a "GET". "OPTIONS" requests are used to upgrade connections to TLS encryption. "POST" requests are used for web interface forms and IPP requests. "PUT" requests are used to upload configuration files. The resource field is the filename of the requested resource. The version field is the HTTP specification version used by the client. For CUPS clients this will always be "HTTP/1.1". The status field contains the HTTP result status of the request, as follows: 200 Successful operation. 201 File created/modified successfully. 304 The requested file has not changed. 400 Bad HTTP request; typically this means that you have a malicious program trying to access your server. 401 Unauthorized, authentication (username + password) is required. 403 Access is forbidden; typically this means that a client tried to access a file or resource they do not have permission to access. 404 The file or resource does not exist. 405 URL access method is not allowed; typically this means you have a web browser using your server as a proxy. 413 Request too large; typically this means that a client tried to print a file larger than the MaxRequestSize allows. 426 Upgrading to TLS-encrypted connection. 500 Server error; typically this happens when the server is unable to open/create a file - consult the error_log file for details. 501 The client requested encryption but encryption support is not enabled/compiled in. 505 HTTP version number not supported; typically this means that you have a malicious program trying to access your server. The bytes field contains the number of bytes in the request. For POST requests the bytes field contains the number of bytes of non-IPP data that is received from the client. The ipp-operation field contains either "-" for non-IPP requests or the IPP operation name for POST requests containing an IPP request. The ipp-status field contains either "-" for non-IPP requests or the IPP status code name for POST requests containing an IPP response. ERROR LOG FILE FORMAT The error_log file lists messages from the scheduler - errors, warnings, etc. The LogLevel directive in the cupsd.conf(5) file controls which messages are logged: level date-time message For example: I [20/May/1999:19:18:28 +0000] [Job 1] Queued on 'DeskJet' by 'mike'. D [20/May/1999:19:18:28 +0000] [Job 1] argv[0]="DeskJet" D [20/May/1999:19:18:28 +0000] [Job 1] argv[1]="1" D [20/May/1999:19:18:28 +0000] [Job 1] argv[2]="mike" D [20/May/1999:19:18:28 +0000] [Job 1] argv[3]="myjob" D [20/May/1999:19:18:28 +0000] [Job 1] argv[4]="1" D [20/May/1999:19:18:28 +0000] [Job 1] argv[5]="media= na_letter_8.5x11in sides=one-sided" D [20/May/1999:19:18:28 +0000] [Job 1] argv[6]="/var/spool/cups/ d000001-001" I [20/May/1999:19:21:02 +0000] [Job 2] Queued on 'DeskJet' by 'mike'. I [20/May/1999:19:22:24 +0000] [Job 2] Canceled by 'mike'. The level field contains the type of message: A Alert message (LogLevel alert) C Critical error message (LogLevel crit) D Debugging message (LogLevel debug) d Detailed debugging message (LogLevel debug2) E Normal error message (LogLevel error) I Informational message (LogLevel info) N Notice message (LogLevel notice) W Warning message (LogLevel warn) X Emergency error message (LogLevel emerg) The date-time field contains the date and time of when the page started printing. The format of this field is identical to the data-time field in the access_log file. The message field contains a free-form textual message. Messages from job filters are prefixed with "[Job NNN]" where "NNN" is the job ID. PAGE LOG FILE FORMAT The page_log file lists each page or group of pages that are sent to a printer. By default, each line contains the following information: printer user job-id date-time page-number num-copies job-billing job-originating-host-name job-name media sides printer user job-id date-time total num-impressions job-billing job-originating-host-name job-name media sides For example the entries for a two page job called "myjob" might look like: DeskJet root 1 [20/May/1999:19:21:05 +0000] 1 1 acme-123 localhost myjob na_letter_8.5x11in one-sided DeskJet root 1 [20/May/1999:19:21:05 +0000] 2 1 acme-123 localhost myjob na_letter_8.5x11in one-sided DeskJet root 1 [20/May/1999:19:21:06 +0000] total 2 acme-123 localhost myjob na_letter_8.5x11in one-sided The PageLogFormat directive in the cupsd.conf(5) file can be used to change this information. The printer field contains the name of the printer that printed the page. If you send a job to a printer class, this field will contain the name of the printer that was assigned the job. The user field contains the name of the user (the IPP requesting-user-name attribute) that submitted this file for printing. The job-id field contains the job number of the page being printed. The date-time field contains the date and time of when the page started printing. The format of this field is identical to the data-time field in the access_log file. The page-number and num-copies fields contain the page number and number of copies being printed of that page. For printers that cannot produce copies on their own, the num-copies field will always be 1. Lines containing the keyword "total" have a num-impressions field instead which provides the total number of impressions (sides) that have been printed on for the job. The job-billing field contains a copy of the job-billing or job-account-id attributes provided with the IPP Create-Job or Print-Job requests or "-" if neither was provided. The job-originating-host-name field contains the hostname or IP address of the client that printed the job. The job-name field contains a copy of the job-name attribute provided with the IPP Create-Job or Print-Job requests or "-" if none was pro- vided. The media field contains a copy of the media or media-col/media-size attribute provided with the IPP Create-Job or Print-Job requests or "-" if none was provided. The sides field contains a copy of the sides attribute provided with the IPP Create-Job or Print-Job requests or "-" if none was provided. SEE ALSO
cupsd(8), cupsd.conf(5), cups-files.conf(5), CUPS Online Help (http://localhost:631/help) COPYRIGHT
Copyright (C) 2007-2017 by Apple Inc. 11 June 2014 CUPS cupsd-logs(5)
All times are GMT -4. The time now is 02:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy