awk - output-data always two numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - output-data always two numbers
# 1  
Old 07-24-2012
awk - output-data always two numbers

Hi,

my data is like the subsequent snipped. Fieldseperator is TAB.
I can work the data well with awk, but the missing zero-numbers at the days column, for the days smaller 10 and the full hour-minutes i cant handle in the output.
Code:
2012  7  1  8 40 249.463 245.01 5.70448 6.11388 6.22125 16.2647
2012  7  1  8 50 260.326 256.423 4.229 4.74559 5.04157 16.2567
2012  7  1  9  0 258.7 252.719 5.14366 6.05517 6.32878 16.0444
2012  7  1  9 10 264.129 260.476 4.41599 5.31431 5.55633 15.9455
2012  7  1  9 20 264.414 258.523 5.03508 5.54373 6.06176 15.9732
2012  7  1  9 30 262.734 253.535 3.85145 4.49508 4.91403 16.3378
2012  7  1  9 40 248.438 243.986 3.88907 4.12355 4.24453 16.5278
2012  7  1  9 50 241.82 241.758 3.44068 3.84172 3.89706 16.6208
2012  7  1 10  0 258.958 255.764 4.08632 4.76283 4.95846 16.8853
2012  7  1 10 10 277.077 270.196 3.80163 4.40679 4.85571 16.7776
2012  7  1 10 20 272.157 265.543 4.56294 5.05318 5.39849 16.639
2012  7  1 10 30 273.282 266.103 4.9927 5.58348 5.70653 16.4421
2012  7  1 10 40 261.78 254.285 3.87303 4.47538 4.46883 16.5397
2012  7  1 10 50 259.434 254.405 4.25445 5.13906 5.47814 16.6506
2012  7  1 11  0 264.879 258.439 5.08236 5.53352 5.91267 16.9551
2012  7  1 11 10 258.885 251.608 4.77117 5.31346 5.35769 17.0515

the output with awk --> date, time and also the following values
awk '{print $3"."$2"."$1 "\t" $4":"$5}' OFS='\t' data.txt

... it should be
Code:
....
2012  7  1  09 40 248.438 243.986 3.88907 
2012  7  1  09 50 241.82 241.758 3.44068 
2012  7  1 10  00 258.958 255.764 4.08632 
2012  7  1 10 10 277.077 270.196 3.80163

Can someone help me, please?
Thanks in Advance!
IMPe
# 2  
Old 07-24-2012
Have a look at the printf() function of awk. Something on these lines:
Code:
awk 'BEGIN{printf("%02d\n",9)}'
09

# 3  
Old 07-24-2012
Hi elixir_sinari

Thank you very much for the hint. It's not looking really nice, but it's working properly.
Code:
awk '{printf("%02d.%02d.%4d\t%02d:%02d\n",$3,$2,$1,$4,$5)}' OFS='\t' file.dat

It's not looking really nice, but it's working properly.

Thanks a lot!
IMPe
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

3. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

4. Shell Programming and Scripting

add numbers to the output based on +/-

Add 35 to the 3rd col (12000) in input if it is "+" and it will be 12035 in output. Some thing like awk '{if ($3==+) print $2,$3,$3+35,$1 else print $2,$3-35,$3,$1}' + abc1 12000 - abc2 10000 + xyz1 11111 - vbcx 20036 + xy_z 33333 output abc1 ... (2 Replies)
Discussion started by: ruby_sgp
2 Replies

5. Shell Programming and Scripting

sed output with numbers

I get the same value "chinchwad" for the following 3 statements. echo "ABCDchinchwad18-Mar-2010-11.sql.zip" | sed -r 's/(+)(+)(.*)/\2/' echo "ABCDchinchwadII18-Mar-2010-11.sql.zip" | sed -r 's/(+)(+)(.*)/\2/' echo "ABCDchinchwad918-Mar-2010-11.sql.zip" | sed -r 's/(+)(+)(.*)/\2/' I expect:... (4 Replies)
Discussion started by: shantanuo
4 Replies

6. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

7. UNIX for Dummies Questions & Answers

Find different column numbers among rows in data

I want to find the different column numbers among rows in a file. For example: A001 a b c d e ... N A002 a b c d e ... N A003 a b c d e ... N+1 A004 a b c d e ... N A005 a b c d e ... N+2 : : For most of the lines I will have N columns (say 1000 rows) in each line except the line 3... (5 Replies)
Discussion started by: AMBER
5 Replies

8. Shell Programming and Scripting

ksh/awk help - output missing numbers

Here is what I am trying to do: I have a list of numbers that I pulled from an awk command in a column like so: 1 3 4 7 8 I want to find which numbers in the list are missing out of a range. So let's say I want to find out from the list above which numbers are missing from the... (6 Replies)
Discussion started by: afavis
6 Replies

9. Shell Programming and Scripting

Sub. numbers in column of output with If

This is my script. I am pulling the status of some hard where, but the status is in numerical form. The number 4 means Major and the 5 means Critical. In my script I would like to show the alarm type in aplha rather than numeric form. So if instead of seeing a 4 or 5 you would see MAjor or... (11 Replies)
Discussion started by: ja156194
11 Replies

10. Shell Programming and Scripting

output only numbers from mixed string

it must be late because I'm sure this is an easy task with grep sed or awk string would be anything mixing numbers letters and ) ( = output I need is just the numbers... but I just can't seem to get it to work. Any tips would be great :) (10 Replies)
Discussion started by: nortypig
10 Replies
Login or Register to Ask a Question