News for hackers. Stuff that matters.
Re:Show HN: Command Line Challenge by cleech on Thursday January 26, 2017 @01:52PM (#13494106)
fun, although I did cheat a bit on the corrupted text and pulled the expected output from README instead of the input file :)
Re:Show HN: Command Line Challenge by zoidb on Thursday January 26, 2017 @01:57PM (#13494163)
The answers I came up with are in https://github.com/jarv/cmdchallenge/blob/master/challenges.... if you are curious.
Re:Show HN: Command Line Challenge by adimitrov on Thursday January 26, 2017 @04:14PM (#13495297)
The awk line for duplicate lines without changing ordering is… wow. Awk is such an underused tool (at least for me.) My solution was:

    awk '{printf "%2d %s\n", NR, $0}' < faces.txt | sort -k 2 -u | sort -n | sed 's/^...//'
Ironically, it also involved awk! But I used it to prepend line numbers, which uniq and sort can ignore, then re-sort it according to line numbers. Very much not an ideal solution!
Re:Show HN: Command Line Challenge by ianmcgowan on Thursday January 26, 2017 @05:22PM (#13495821)
Mine was more procedural - store each line in a hash as you visit it, and only print lines you haven't already visited. awk is awesome ;-)

awk '!h[$0] {h[$0]=1; print}' faces.txt

Re:Show HN: Command Line Challenge by schoen on Thursday January 26, 2017 @05:58PM (#13496159)
I also used this approach but the original creator's version posted on GitHub is remarkably more concise (due to a clever use of the ++ operator).
Re:Show HN: Command Line Challenge by ianmcgowan on Thursday January 26, 2017 @08:16PM (#13496946)
awk '!h[$0]++' faces.txt

That is clever! Awk golf hole-in-one ;-)

Re:Show HN: Command Line Challenge by jenrzzz on Thursday January 26, 2017 @08:48PM (#13497095)
I love awk. I used to be afraid of it, but I started using it just to pluck columns, and over a couple years actually started to grok it.

Also, I learned today that cat takes a -n option to prepend line numbers to the output! My solution ended up being

    cat -n faces.txt | sort -k2 -k1n | uniq -f1 | sort -nk1,1 | cut -f2-
Re:Show HN: Command Line Challenge by MrQuincle on Thursday January 26, 2017 @06:28PM (#13496378)
That was a tough one. In the end something like this:

< war_and_peace.txt tr -s '!' | sed 's/!\([a-z]\)/\1/g' | sed 's/!\( [a-z]\)/\1/g' | sed 's/!\.!/./g' | sed 's/ !/ /g'

However, I don't think I learnt much from that. :-)

Re:Show HN: Command Line Challenge by arde on Thursday January 26, 2017 @10:08PM (#13497395)
Mine was a bit more procedural, if that's what you were looking for:

  awk '{l++;gsub("!","");t[1]=4;t[4]=2;t[9]=3;o=$1;for(i=2;i<=NF;i++){o=o " " $i (i==t[l]?"!":"")};print o}' war_and_peace.txt
Re:Show HN: Command Line Challenge by JoshTriplett on Thursday January 26, 2017 @02:20PM (#13494372)
The description for remove_duplicate_lines needs some clarification, because as written it sounds like either "uniq" or "uniq -u". You should explicitly say that you want the first instance of every duplicated line printed, and all other duplicates not printed, even if not adjacent.
Re:Show HN: Command Line Challenge by zoidb on Thursday January 26, 2017 @02:25PM (#13494410)
Thanks, also feel free to send a pull requests as I would definitely appreciate contributions.
Re:Show HN: Command Line Challenge by MrQuincle on Thursday January 26, 2017 @06:32PM (#13496413)
Ah, I thought you knew seq had a delimiter option! It does actually. :-)

    seq -s ' ' 1 100
Re:Show HN: Command Line Challenge by helb on Friday January 27, 2017 @05:40AM (#13498958)
Just "echo {1..100}" works too.