[PLUG] An awk-ward Question

Robert Citek robert.citek at gmail.com
Tue Mar 22 23:59:29 UTC 2011


Would this work?

echo "BC-2:2009-02-15:Flow:150.00:ft/sec:Temperature
(field):7.40:oF:Conductance,Specific:2058.00:umhos/cm:pH:7.40:Std
Units" |
awk -F: '{
print $1":"$2":"$3":"$4":"$5 ;
print $1":"$2":"$6":"$7":"$8 ;
print $1":"$2":"$9":"$10":"$11 ;
print $1":"$2":"$12":"$13":"$14 ;
}'

The same in perl:

echo "BC-2:2009-02-15:Flow:150.00:ft/sec:Temperature
(field):7.40:oF:Conductance,Specific:2058.00:umhos/cm:pH:7.40:Std
Units" |
perl -F: -lane '
print join(":", at F[0,1,2,3,4]) ;
print join(":", at F[0,1,5,6,7]) ;
print join(":", at F[0,1,8,9,10]) ;
print join(":", at F[0,1,11,12,13]) ;
'

Regards,
- Robert

On Tue, Mar 22, 2011 at 4:32 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
>   I have a text file whose rows are formatted like this:
>
> BC-2:2009-02-15:Flow:150.00:ft/sec:Temperature (field):7.40:oF:Conductance,
> Specific:2058.00:umhos/cm:pH:7.40:Std Units
> BC-2:2009-05-15:Flow::ft/sec:Temperature (field):10.10:oF:Conductance,
> Specific:1224.00:umhos/cm:pH:8.14:Std Units
> BC-3:2009-02-15:Flow:326.00:ft/sec:Temperature (field):7.80:oF:Conductance,
> Specific:576.50:umhos/cm:pH:7.40:Std Units
>
> and I need to have them split into multiple rows. Each row would have field
> #1, a colon separator, field #2, a colon separator, then the parameter name,
> measured value, and units. A job for awk!
...



More information about the PLUG mailing list