Skip to main content

Posts

Showing posts with the label awk

[awk] convert K, M, G to byte in string

p1 file 1.2G /home/parkmo 0.5M /home/parkmo/tmp ------------------------------------------ Output 1288490188 /home/parkmo 524288 /home/parkmo/tmp ------------------------------------------ ---- the script ----- cat p1 | awk '{ TEXT1=$1; TEXT2=$2;  SEP=substr(TEXT1, length(TEXT1), length(TEXT1));  STR_VALUE=substr(TEXT1, 0, length(TEXT1-1)); # print SEP; # print STR_VALUE;  if ( SEP == "K" )  { VALUE=STR_VALUE*1024 }  else if ( SEP == "G")  { VALUE=STR_VALUE*1024*1024*1024 }  else if ( SEP == "M")  { VALUE=STR_VALUE*1024*1024 }  else { VALUE=STR_VALUE } printf("%d %s\n", VALUE, TEXT2) } '