Hi all
I want to do a simple substitution in awk but I am getting unexpected output. My function accepts a time and then prints out a validation message if the time is valid. However some times may include a : and i want to strip this out if it exists before i get to the validation. I have shown a small sample of my function below which is giving the unexpected output. When this function is called with 23:01 the first print time gives 23:01 but the second gives a 1. What i want is simply 2301.
Can anyone let me know what im doing wrong.
function getTime(time)
{
print time;
time = gsub(":","x",time);
print time;
}
gsub(r, s [, t]) For each substring matching the regular expression r in the
string t, substitute the string s, and return the number of
substitutions. If t is not supplied, use $0. An & in the
replacement text is replaced with the text that was actu*
ally matched. Use \& to get a literal &. (This must be
typed as "\\&"; see GAWK: Effective AWK Programming for a
fuller discussion of the rules for &'s and backslashes in
the replacement text of sub(), gsub(), and gensub().)