![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array inside an array | manas_ranjan | UNIX for Advanced & Expert Users | 5 | 06-10-2008 02:25 PM |
| Access value outside awk or split value of array | jason.bean | UNIX for Dummies Questions & Answers | 1 | 11-26-2007 04:33 PM |
| How to get array to not split at spaces? | jjinno | Shell Programming and Scripting | 1 | 07-20-2007 12:06 AM |
| split to array in perl | jaganadh | Shell Programming and Scripting | 3 | 07-06-2007 05:29 AM |
| looping a array inside inside ssh is not working, pls help | reldb | Shell Programming and Scripting | 5 | 07-07-2006 10:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
split and making an array inside another array
I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be??
e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 Code:
awk '
NR==FNR{
a[NR]=$0
next
}
{
for(i=1;i<NR;i++)
split($0,a[i],":"); print a[i][2]
}'
![]() edit also will this substring from the split come out of the slit function as a number? e.g. can I do math on it or will it be a 'word'? If its a word can I make it a number? Last edited by jim mcnamara; 08-06-2008 at 10:02 AM.. Reason: code tags |
|
||||
|
try this: setting a field separator.
Code:
awk -F: '{ a[FNR]=$1; b[FNR]=$2; c[FNR]=$3 }
END{
for(i in a) { hour+=a[i]}
for(i in b) { min+=b[i]}
for(i in c) { sec+=c[i]}
printf "hours=%d min=%d sec=%d\", hour, min,sec)
} ' inputfile
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|