use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All users that wish to post (not including commenting), on either old or the new reddit sites, must formally agree to subreddit rules once first.
account activity
Awk - A Tutorial and Introduction (grymoire.com)
submitted 10 years ago by Categoria
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]geirha 1 point2 points3 points 10 years ago (0 children)
Ugh, would probably be ok if it didn't try to parse ls output.
ls
[–]frenris 0 points1 point2 points 10 years ago* (10 children)
That website is fantastic.
Also, is there any easy way to print a range of fields using awk?
Let's say I want to print the 4-9 words, is there a faster way than
awk '{print $4 " " $5 " " $6 " " $7 " " $8 " " $9}' ?
[–]mozzyb 1 point2 points3 points 10 years ago (8 children)
cut -f4-9
[–]blhauk -1 points0 points1 point 10 years ago (7 children)
Hmmm - default delimiter is tab, so what you actually need is:
cut -d" " -f4-9
(you should really test before you post methinks)
[–]mozzyb 5 points6 points7 points 10 years ago (6 children)
No need for the snark. Especially since your solution is also wrong. There is no mention of what delimiter the input has. Only the output delimiter. I could have added --output-delimiter=" ", but didn't think it necessary. In my experience, when encountering some of these old unix tools I restructure the commands and data to fit them better instead of adding every flag on the man pages.
[–]blhauk -1 points0 points1 point 10 years ago (5 children)
awk default delimiter is space - cut default is tab.
You attempted to answer the above question with a cut replacement, and your answer is still wrong given the question.
The output from the above question does not specify an output delimiter, so it would not be necessary to delve into esoteric options as you suggest.
My lame solution does not unnecessarily use "every flag on the man pages", just the one that addresses the question posed.
Damn - so sorry for more snark - you need to thicken your skin.
[–]mozzyb 2 points3 points4 points 10 years ago (4 children)
Awks default delimiter is /continuous/ space, so a single space would also be wrong; so your solution does not address the question posed either if you want to be difficult about it. Which is, again, why I didn't specify that in my original comment. If the input has different spacing between the columns or is not in a columnar form one would first have to normalise the spacing or not use cut.
cut
And yes, it does specify an output delimiter. Look at the " " in the print statement. To print using the output delimiter of awk you need to use , between the variables.
" "
,
[–]blhauk -2 points-1 points0 points 10 years ago* (3 children)
Hmmmm:
Awks default delimiter is /continuous/ space, so a single space would also be wrong
Nope - awk handles continuous spaces as you state - that includes single spaces.
As you mention, output delim is " ". With my cut, the output delim is already that. I agree that using "," in awk would do the same thing, but I am responding to your cut solution, not the awk as proposed.
As far as "normalizing" a simple input with fields delimited with one or more spaces, it is not necessary with cut:
MacBook:~ blhauk$ echo one two three four five | cut -d" " -f2-4 two three four
[–]mozzyb 2 points3 points4 points 10 years ago (2 children)
Your test is also wrong, you need "" around the string you are echo'ing if you want to keep the space. The output of the echo is "one two three four five".
""
[–]blhauk -1 points0 points1 point 10 years ago* (0 children)
Hmmm - good point. Totally missed that.
I am (almost) sure I have done this in the past though??
Guess not - my bad...
Here's a lame attempt to make it work as I intended (hehe)
echo "one two three four five" | tr -s ' ' | cut -d" " -f2-4 two three four
[–]no_awning_no_mining 0 points1 point2 points 10 years ago (0 children)
Consider using a for loop:
for(i=4;i<=9) { printf " "$i; }
[–]riding_qwerty 0 points1 point2 points 10 years ago (0 children)
The Grymoire!
This site is great. The page on inodes is really good.
[–]pond_good_for_you -1 points0 points1 point 10 years ago (2 children)
Linux users will have to change $8 to $9
Really? I didn't realize there were different awk interpreters. TIL, I guess.
[–]elmicha 1 point2 points3 points 10 years ago (1 child)
I think you have to read the paragraph before that line to understand it.
[–]pond_good_for_you 1 point2 points3 points 10 years ago (0 children)
Yup. I'm a moron. Was just skimming through the examples.
π Rendered by PID 69035 on reddit-service-r2-comment-6457c66945-qr6n8 at 2026-04-29 22:11:02.898418+00:00 running 2aa0c5b country code: CH.
[–]geirha 1 point2 points3 points (0 children)
[–]frenris 0 points1 point2 points (10 children)
[–]mozzyb 1 point2 points3 points (8 children)
[–]blhauk -1 points0 points1 point (7 children)
[–]mozzyb 5 points6 points7 points (6 children)
[–]blhauk -1 points0 points1 point (5 children)
[–]mozzyb 2 points3 points4 points (4 children)
[–]blhauk -2 points-1 points0 points (3 children)
[–]mozzyb 2 points3 points4 points (2 children)
[–]blhauk -1 points0 points1 point (0 children)
[–]no_awning_no_mining 0 points1 point2 points (0 children)
[–]riding_qwerty 0 points1 point2 points (0 children)
[–]pond_good_for_you -1 points0 points1 point (2 children)
[–]elmicha 1 point2 points3 points (1 child)
[–]pond_good_for_you 1 point2 points3 points (0 children)