multiple and diferent printf(s) for diferent fields in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple and diferent printf(s) for diferent fields in awk
# 1  
Old 01-06-2012
multiple and diferent printf(s) for diferent fields in awk

Hi,

I'm trying to print and outrput of a timestamp from a script i did that calcs de time diference betwen 2 timestamps in the format HH:MM:SS and i properly formated it with printf inside awk, but i can't do it with separate statements.

This works fine, but can you explaim-me how to do it in a single statment? Smilie
Code:
echo "$E2H" | awk '{printf "%02d", $1}{printf ":"}'
echo "$E2M" | awk '{printf "%02d", $1}{printf ":"}'
echo "$MOD" | awk '{printf "%02d", $1}'

This dont work. I want a single statment inside awk or some other alternative way. Using korn88 shell in a standard unix awk, no gnu tools, it's HP-UX 11

Code:
echo "$E2H:$E2M:$MOD" | awk 'FS=":" {printf "%02d", $1}{printf ":"}{printf "%02d", $2}{printf ":"}{printf "%02d", $3}'


Cheers,
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 01-06-2012 at 08:04 AM.. Reason: code tags, please!
# 2  
Old 01-06-2012
Code:

echo "$E2H:$E2M:$MOD" | awk -F: '{printf ("%02d:%02d:%02d\n", $1,$2,$3)}'

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 01-09-2012
Thankz, i will use it as soon i get to work Smilie

Cheers,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print multiple fields with awk

so its common knowledge one can print multiple fields with simple commands like this: echo 12 44 45 552 24 | awk '{print $1,$4,$3}' but suppose i want to avoid specifying the "$" symbol. is that possible? can something like this be done: echo 12 44 45 552 24 | awk '{print $(1,4,3)}' ... (9 Replies)
Discussion started by: SkySmart
9 Replies

2. Shell Programming and Scripting

Replace 0 with 1 in multiple fields with awk

Hello, I have the following input file: 1 3 3 2 3 3 4 0 4 0 5 4 5 2 2 0 5 3 4 0 6 0 3 2 I am trying to remove all zeroes in fields 2 and 4 and replace them with "1's" I tried the following, but it's not working awk -F"\t" '{ if (($2==0) || ($4==0) $2=1; $4=1; print $0 ) }' input ... (8 Replies)
Discussion started by: Rabu
8 Replies

3. Shell Programming and Scripting

Connection to diferent server

Hello I'm conecting in server1 and I need connect to server2(other). I need doing that becouse I need run a lot bach of diferent serverX. I explain better: Connectionn server1 ## I need that all the step exit for xxx.txt of the server1 - run xxxx.sh - Conection server2 - su -... (1 Reply)
Discussion started by: bsebastian
1 Replies

4. Shell Programming and Scripting

awk multiple fields separators

Can you please help me with this .... Input File share "FTPTransfer" "/v31_fs01/root/FTP-Transfer" umask=022 maxusr=4294967295 netbios=NJ09FIL530 share "Test" "/v31_fs01/root/Test" umask=022 maxusr=4294967295 netbios=NJ09FIL530 share "ENR California" "/v31_fs01/root/ENR California"... (14 Replies)
Discussion started by: greycells
14 Replies

5. Shell Programming and Scripting

awk gsub multiple fields

Hi, I am trying to execute this line awk -F ";" -v OFS=";" '{gsub(/\./,",",$6); print}' FILE but for multiple fields $6 $7 $8 Do you have a suggstion? Tried: awk -F ";" -v OFS="";"" "function GSUB( F ) {gsub(/\./,\",\",$F); print} { GSUB( 6 ); GSUB( 7 ); GSUB( 8 ) } 1"... (2 Replies)
Discussion started by: nakaedu
2 Replies

6. Shell Programming and Scripting

awk to grep rows by multiple fields

Hello, I met a challenge to extract part of the table. I'd like to grep the first three matches based on field1 and field2. Input: D A 92.85 1315 83 11 D A 95.90 757 28 3 D A 94.38 480 20 7 D A 91.21 307 21 6 D A 94.26 244 ... (6 Replies)
Discussion started by: yifangt
6 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

AWK multiple fields separators

I need to print the second field of a file, taking spaces, tab and = as field separators. ; for 16-bit app support MAPI=1 CMC=1 CMCDLLNAME32=mapi32.dll CMCDLLNAME=mapi.dll MAPIX=1 MAPIXVER=1.0.0.1 OLEMessaging=1 asf=MPEGVideo asx=MPEGVideo ivf=MPEGVideo m3u=MPEGVideo (2 Replies)
Discussion started by: PamPam
2 Replies

9. Linux

Makefile with sources in diferent folders

Hi guys! I have a problem to create a makefile when using 2 types of sources. Suppose we have sources at master_source folder: - 1.c - 2.c and also we have sources at platform_source folder: - 1.c I really need to use platform_source folder because there is many of them (one folder with... (8 Replies)
Discussion started by: borzh62
8 Replies

10. UNIX for Dummies Questions & Answers

Subtract date & time in diferent rows

Hi Friends :) I have a long file having fields in the form : Field1 yy/mm/dd hh:mm:ss Duration(Sec) line 1) 123123 05/11/30 12:12:56 145 line 2) 145235 05/11/30 12:15:15 30 line 3) 145264 05/11/30 13:14:56 178 . . I want to subtract yy/dd/dd hh:mm:ss in line (2) from yy/mm/dd hh:mm:ss in... (1 Reply)
Discussion started by: vanand420
1 Replies
Login or Register to Ask a Question