Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Format a date on additional column awk Post 303031801 by Don Cragun on Wednesday 6th of March 2019 03:18:44 AM
Old 03-06-2019
Expanding a little bit on what RudiC said ....

It looks like the file you are processing is partially in DOS text file format with some <carriage-return> <newline> character pair line separators instead of UNIX text file format <newline> single character line terminators. But, as RudiC said, we would expect that to happen on every line; not just the first and last.

Please confirm by running the command:
Code:
od -bc filename

where filename is the name of the input file you processed to get the output you showed us in post #7 in this thread.

To get rid of the <carriage-return>s in a file you can use:
Code:
tr -d '\r' < old_file > new_file

where old_file is the name of a file containing <carriage-return>s and new_file is the name of thee file that you want to contain the contents of old_file without the <carriage-return>s. If this is a common problem with input files you'll be processing, you can change the script I suggested before to be:
Code:
#!/bin/ksh
tr -d '\r' < HB.txt | while IFS=, read -r date rest
do	printf '%s,%s,%(%a)T\n' "$date" "$rest" "$date"
done

or:
Code:
#!/bin/ksh
while IFS=, read -r date rest
do	printf '%s,%s,%(%a)T\n' "$date" "$rest" "$date"
done < HB.txt | tr -d '\r'

This User Gave Thanks to Don Cragun For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

2. UNIX for Dummies Questions & Answers

Format Date in awk

I have an assignment in a Linux class I am taking. It has multiple scripts. Basicly when it runs it asks the user name and shows information about the user from the /etc/passwd and /etc/shadow files. The one I need help with is the one that reads the /etc/shadow file. I need to format the date into... (1 Reply)
Discussion started by: kazulk
1 Replies

3. Shell Programming and Scripting

Convert the date format from mdy to ymd in column of file

The date format in the delimited file for one column '6/27/2011 12:00:00 AM' Is it possible o change it to '2011-06-27 12:00:00 AM' for all the records.. Thanks in advance..... (8 Replies)
Discussion started by: infernalhell
8 Replies

4. Shell Programming and Scripting

awk compare column with date format

I have this code to compare columns 1 and 10 between file1 and file 2 and give me all records that match column 1 but dont match column 10 However column 10 is date format mm/dd/yy and awk cant read it and compare ...i tried awk < file1 -F~ '{print $10}' and it gave blank screen Is... (1 Reply)
Discussion started by: sigh2010
1 Replies

5. Shell Programming and Scripting

awk - change date format

I have below date format in a CSV file. (dd/mm/yyyy) Ex Input: 9/8/2013 Need to convert it into below format (yyyymmdd ) and redirect to new file. Ex Output: 20130809 How do I use awk here to change the format and if leading 0 (zero) is not then add it. Please help. Thanks. (8 Replies)
Discussion started by: vegasluxor
8 Replies

6. Shell Programming and Scripting

awk convert date format

Could you tell me how to convert the following dates? If I have m/d/yyyy, I want to have 0m/0d/yyyy. I want my dates to always be 8 digits. In other words, I want a 0 inserted whenever the month or day is a single digit. My issue is first I need to use FS="," to get field $4 for the... (7 Replies)
Discussion started by: wbrunc
7 Replies

7. Shell Programming and Scripting

Convert date column as yyyy/mm/dd format

Hi All, I have file like “April 10, 2013”,”raj” “April 29, 2013”,”raj1” Output : “2013/04/10”,”raj” “2013/04/29”,”raj1” Please help me how to do... (9 Replies)
Discussion started by: bmk
9 Replies

8. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

9. Shell Programming and Scripting

How to awk or grep the last column in file when date on column contains spaces?

Hi have a large spreadsheet which has 4 columns APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96034 Storage Mgmt Team APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies
pilot-install-dat(1)						    PILOT-LINK						      pilot-install-dat(1)

NAME
pilot-install-datebook - Installs one or more new datebook entries onto your Palm handheld. SECTION
pilot-link: Userland conduits SYNOPSIS
pilot-install-datebook [-p|--port <port>] [--version] [-?|--help] [-q|--quiet] [--usage] [-r|--read file] DESCRIPTION
pilot-install-datebook allows the user to create one or more datebook entries from one or more source files. The format of the source file contains one datebook entry per line, containing four tab separated fields. The fields are start date/time, end date/time, alarm settings, and the description of datebook entry. This program doesn't yet support repeated entries. The date and time must be in format understood by parsedate.y. At the very least, the following two formats are understood: August 11, 1997 0800 GMT+300 1997/08/11 08:22:33 GMT+300 If either one of the date and time fields is empty, the entry is installed without time. If the alarm field is empty, the entry is installed without setting any alarms. The alarm field can contain numbers followed by "m" (minutes), "h" (hours), or "d" (days). OPTIONS
pilot-install-datebook options -r, --read Read entries from file. Conduit Options -p, --port <port> Use device file <port> to communicate with the Palm handheld. If this is not specified, pilot-install-datebook will look for the $PILOTPORT environment variable. If neither are found, pilot-install-datebook will print the usage information. -q, --quiet Suppress 'Hit HotSync button' message --version Display the copyright information, version number, license details and build details and exit without connecting. Help options -?, --help Show the help message and exit without connecting. --usage Display a brief usage message and exit without connecting. USAGE
The program will connect to the target Palm device, and create Datebook entries based on the datebook-formatted file given on the command- line onto the Palm handheld (into the DatebookDB.pdb file). EXAMPLES
([__TAB__] = tab, [__NL__] = newline in these examples): 1997/08/11 0800 GMT+300 [__TAB__] 1997/08/11 0900 GMT+300 [__TAB__] [__TAB__] IETF Registration [__NL__] August 11, 1997 0900 GMT+300 [__TAB__] August 11, 1997 0930 GMT+300 [__TAB__] 2m [__TAB__] Introductions [__NL__] AUTHOR
pilot-install-datebook was originally written by Tero Kivinen <kivinen@iki.fi>. This program was based on pilot-install-todos program written by Robert A. Kaplan <kaplan@openmarket.com>. This manual page was converted to XML by Neil Williams <linux@codehelp.co.uk> BUGS
Known Bugs If no timezone is given, pilot-install-datebook will assume the time is in GMT and it will convert it to localtime. If you don't want to create timezone entries for all begin and end times, set the TZ environment variable to GMT before running this program. Reporting Bugs We have an online bug tracker. Using this is the only way to ensure that your bugs are recorded and that we can track them until they are resolved or closed. Reporting bugs via email, while easy, is not very useful in terms of accountability. Please point your browser to http://bugs.pilot-link.org: http://bugs.pilot-link.org and report your bugs and issues there. COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. SEE ALSO
pilot-install-todos(1), pilot-link(7). 0.12.5 Copyright 1996-2007 FSF pilot-install-dat(1)
All times are GMT -4. The time now is 04:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy