05-28-2009
Hi,
Kindly assist by analyzing my code below and suggest the changes to achieve the required output.
The input file:
01-010241800000 35000 MV010 02/03/09 0306 03060226 03
02-004103300000 470000 MV010 02/03/09 0301 03010276 03
Then I pass it on to:
awk 'BEGIN {OFS=" " }
{ split($4,arr,"/");
$4=sprintf("%d%s%s",arr[2]+2000,arr[1],arr[0])
print $0} '
The output comes as:
01-010241800000 35000 MV010 200302 0306 03060226 03
02-004103300000 470000 MV010 200302 0301 03010276 03
sprintf, truncates the 2009 and instead returns a value of 20 for arr[2]. I guess arr[2] should be of length 4 as opposed to it's original length of 2. Would someone kindly help decipher why I am losing the "09" on arr[2]?
Much Regards
Pawee.
Last edited by talk2pawee; 06-02-2009 at 07:39 AM..
Reason: Make the issue much clearer for support analysis.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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
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
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
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
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
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
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
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
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