Quote:
Originally Posted by
bstrizzy
Wow. Thanks to Chubler_XL
and RavinderSingh13
. All of the solutions worked perfectly.
In order to understand this further and practice with 'awk' do you guys recommend any websites/videos/books for tutorials and practice?
Start with the
awk man page. (Use the command:
man awk to get the
awk man page on your system.)
Quote:
Bryan S
---------- Post updated at 07:19 PM ---------- Previous update was at 04:23 PM ----------
Chubler_XL I am testing this code and Can you please add documentation to this code?
I am trying to make sense of this and I can only make out:
Line 1 : initiating the awk command and setting the Number of Fields to 2, Why is this being done?
If it was setting the number of fields, it would be using
= instead of
==. This is a test that selects input lines that contain two fields. If the test evaluates to TRUE, the commands between
{ and the matching
} will be executed for this input line. So, in this case all of the commands in this script are executed in order for every line that has two input fields and all other lines are ignored.
Quote:
Line 2: We are printing everything in the first field to lowercase but I am unsure what the "%s" represents
Look at the
awk or
printf man page for a description of format specifiers in the format string argument to the
printf function. In this case,
%s prints a string specified by the next argument and then prints a space following that.
Quote:
Line 3: creating the variable count and setting it equal to splitting what is in field 2 and using the "," as a delimiter. What does the ",users," represent?
Unquoted commas separate arguments in any function call. Look at the
awk man page. The 1st argument to
split tells it what string is to be split; the 2nd argument specifies the name of an array that is to contain the fields that are split out of the 1st argument; and the 3rd argument, if there is one, specifies the extended regular expression that is used to identify the field separators.
Quote:
Line 4: creating a for loop with random variable 'u' starts at 1 it continues until it has hit the entire count of the second field and 'u' is set to increase 1 everytime. each time it goes through this loop it will print "(,%s,)",users[u]?
Again, look at the
awk or
printf man page to see how the
printf function format string argument works. Do not ignore the space in that format argument. As you requested, this loop prints each array element split from the 2nd field on the current input line preceded by a space and the characters
(, and followed by
,).
Quote:
Line 5: prints a new line
Line 6: using infile and sending output to infile.fixed
I would say "reading from" instead of "using", but you get the idea.
Quote:
Can you help me fill in my blanks?
Thanks!
B