Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Conversion problem with date field and formatting. Post 302320317 by talk2pawee on Wednesday 27th of May 2009 04:22:58 PM
Old 05-27-2009
Conversion problem with date field and formatting.

Hi,

My input file contains the record(s) as below with space as FS.

01-01024180 35000 MV010 02/03/09 0306 03060226 03
02-00410330 470000 MV010 02/03/09 0301 03010276 03

1. I need to convert the field 02/03/09 (dd/mm/yy) to yyyymmdd yet retain the Field separator.

Using the modified code below(previous solution by Vgersh99 to Debian):

BEGIN {
FS=OFS=" "
PAT_percent="%"
# 'LENGTH of the fields'
split("-15 17 5 8 5 15 2", arrL, " ")
# 'TYPE of the fields"
split("s d s d s d s", arrT, " ")
}

{
for(i=1; i <= NF; i++) {
format=sprintf("%c%c%d%s%s", PAT_percent, (arrT[i] == "s") ? "-" : "0", arrL
[i], arrT[i], (i<NF) ? OFS : "\n")
printf(format, $i)
}
}

I get the output as:
01-01024180 00000000000035000 MV010 00000002 0306 000000003060226 03
02-00410330 00000000000470000 MV010 00000002 0301 000000003010276 03

Yet my intention is to get an output like:
01-01024180000000000000000035000MV010200903020030600000000306022603
02-00410330000000000000000470000MV010200903020030100000000301027603

Each record appearing as one single continuous line without field separators.
Would someone kindly guide.Smilie
Much Regards!

Pawee.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

date conversion

Hi everybody: Could anybody tell me how I convert from a julian date, with shell comands, to gregorian. Thanks in advance. (2 Replies)
Discussion started by: tonet
2 Replies

2. Shell Programming and Scripting

Date Conversion

Hi, Does anyone know (in KSH, CSH, SED or AWK), how to convert date text in a file from: EX: May232008 to: 05232008 Thanks, (3 Replies)
Discussion started by: jgrant746
3 Replies

3. Shell Programming and Scripting

CSV formatting with prefixing, appending and padding field

Hi I have a very large csv file with some hundreds of thousands of rows of data. The data is in the following format: Up to four alpha numeric characters for the first word. This is either set as 2 characters followed by 2 spaces, or as a single 4character word. This is then followed by an 8... (7 Replies)
Discussion started by: meself
7 Replies

4. Shell Programming and Scripting

Conversion of date to Julian date

Hi Gurus, Need help in Conversion of date(2007-11-30) to Julian date(YYDDD)... '+%J' 2007-11-30 to 'YYDDD' Thanks (4 Replies)
Discussion started by: SeenuGuddu
4 Replies

5. Shell Programming and Scripting

Delimted to padded conversion with unknown field length

I’m looking for an elegant way to convert a delimited file (comma delimited in this case) to padded columns (for printing in non-proportional font) but the length of each column is not known ahead of time. It needs to be calculated for each column from the longest entry in that column in a given... (3 Replies)
Discussion started by: Michael Stora
3 Replies

6. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

7. Shell Programming and Scripting

Julian date to Calendar date conversion

Hi all, I require to convert julian date to normal calander date in unix for eg julian date=122 now i want corresponding calander date ---------------------------------------- gr8 if give very small command/script and please explain the steps as well(imp) Thanks ... (3 Replies)
Discussion started by: RahulJoshi
3 Replies

8. Shell Programming and Scripting

Adding a field to a file using a conversion table

Hello everyone, Here is what i am trying to accomplish. I have a transaction log that I want to to add a field. The fields in the transaction log are tab delimited FYI. My goal is to add a column specifying the category/type to each item purchased. I have created a two column "conversion table"... (2 Replies)
Discussion started by: SpencerClark
2 Replies

9. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

10. Shell Programming and Scripting

Update a field using awk and keep the formatting.

Look at this simple example. echo " 2 4 6" | awk '{$2+=3;$3-=1}1' 2 7 5 Is there a simple way to update a field and at the same time keep the formatting? I would like to get it like this 2 7 5 I have tested both sub and gsub, it reformat too. (2 Replies)
Discussion started by: Jotne
2 Replies
PX_GET_RECORD(3)														  PX_GET_RECORD(3)

px_get_record - Returns record of paradox database

SYNOPSIS
array px_get_record (resource $pxdoc, int $num, [int $mode]) DESCRIPTION
PARAMETERS
o $pxdoc - Resource identifier of the paradox database as returned by px_new(3). o $num - The record number is an artificial number counting records in the order as they are stored in the database. The first record has number 0. o $mode - The optional $mode can be PX_KEYTOLOWER or PX_KEYTOUPPER in order to convert the keys of the returned array into lower or upper case. If $mode is not passed or is 0, then the key will be exactly like the field name. The element values will contain the field values. NULL values will be retained and are different from 0.0, 0 or the empty string. Fields of type PX_FIELD_TIME will be returned as an integer counting the number of milliseconds starting at midnight. A timestamp ( PX_FIELD_TIMESTAMP) and date ( PX_FIELD_DATE) are floating point respectively int values counting milliseconds respectively days starting at the beginning of julian calendar. Use the functions px-timestamp2string(3) and px-date2string(3) to convert them into a character representation. RETURN VALUES
Returns the $num'th record from the paradox database. The record is returned as an associated array with its keys being the field names. SEE ALSO
px_retrieve_record(3). PHP Documentation Group PX_GET_RECORD(3)
All times are GMT -4. The time now is 01:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy