draw rhomb

a=$(b=$(($LINES/2));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr '\t' ' ');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '

1
By: knoppix5
2015-04-08 02:33:05

These Might Interest You

What Others Think

Ooh, that's pretty, but I need to sleep :-)
flatcap · 163 weeks and 4 days ago
You command looked quite simple to start with. Then I noticed a spare ) and realised how devious it was! My first attempt is a bit more linear (and slightly smaller) L=$((LINES/2)) function f() { for A in $(seq $L); do for B in $(seq $L); do [ $A -lt $B ] && C=' ' || C=x echo -n "$C " done echo done } X=$(f | tac; f) paste <(echo "$X") <(echo "$X" | rev) | sed 's/\t //' The function f draws the bottom-left quadrant. Then I use tac and rev to reflect my way to the others. It compresses down to: L=$((LINES/2));f(){ for A in $(seq $L);do for B in $(seq $L);do [ $A -lt $B ]&&C=' '||C=x;echo -n "$C ";done;echo;done };X=$(f|tac;f);paste <(echo "$X") <(echo "$X"|rev)|sed 's/\t //' That's 183 characters against your 210.
flatcap · 163 weeks and 4 days ago
This new version starts with the middle line: x (lots of space) x then repeatedly replaces with whitespace with x (less space) x S=$((LINES*2-3)) L=$(printf "x%${S}sx" "") function g() { for A in $(seq $((LINES/2))); do echo "$L" L=$(echo "$L" | sed 's/ \( \+\)/ x\1x /') done } g | tac g Compressed: 159 characters: S=$((LINES*2-3));L=$(printf "x%${S}sx" "");function g(){ for A in $(seq $((LINES/2))); do echo "$L";L=$(echo "$L" | sed 's/ \( \+\)/ x\1x /');done };g|tac;g
flatcap · 163 weeks and 4 days ago
My last attempt was: a=$(b=$(($LINES/2-1));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr '\t' ' ');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '|sed 's/x \| x/+/g' but, probably being too long, uploaded and copied back from web behaved distorted. Probes with sed 's/^\|$/x/g' in combination with variable string length failed. In command simile to echo {1..10..2} replacing '10' with variable i.e. $b is not possible, so archaic seq behaves better this way. @flatcap: Your "compressed: 159 characters long" command doesn't work for me (distorted output), but this another one "183 characters long" is fine.
knoppix5 · 163 weeks and 4 days ago
The important (but squashed) part of my command was 4 spaces in the sed: ... | sed 's/ \( \+\)/ x\1x /' sed space single-quote s slash space space space space backslash open-bracket space backslash plus backslash close-bracket slash space x backslash 1 x space slash single-quote My next command will be something to transliterate shell-commands into English. Try1: https://gist.github.com/flatcap/7e44ac26e150cd10511b Try2: https://gist.github.com/flatcap/d475cd45bcc5a5f126b7
flatcap · 163 weeks and 3 days ago
Ah. I can get your latest command to work, by making a couple of tweaks. In the paste, change the fourth clause from: <(f)|tr '\t' ' ') to <(f)|tr -d '\t') Then remove the final sed: |sed 's/x \| x/+/g' Leaving: a=$(b=$(($LINES/2-1));f() { for c in $(seq $b); do for i in $(seq $c);do echo x;done|xargs echo;done };paste <(f) <(f|tac|tr 'x' '-') <(f|tac|tr 'x' '-') <(f)|tr -d '\t');(cat <<<"$a"|tac;cat <<<"$a")|tr '-' ' '
flatcap · 163 weeks and 3 days ago
I see. While copy-paste process web to terminal and vice versa sed is loosing spaces - cause your/mine last command didn't obey.
knoppix5 · 163 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: