Sponsored Content
Top Forums Shell Programming and Scripting awk diamond code golf (just for fun!) Post 302986573 by RudiC on Sunday 27th of November 2016 02:24:59 PM
Old 11-27-2016
Interesting effect when applied to Don Cragun's text example:
Code:
awk -vW=30 -vL="Happy New Year" 'BEGIN{for(i=k=1;i>=1;i+=k) {printf("%*.*s\n",(W/2)+i,i*2-1,L);if(i>=W/2)k=-1}}'
               H
              Hap
             Happy
            Happy N
           Happy New
          Happy New Y
         Happy New Yea
         Happy New Year
          Happy New Year
           Happy New Year
            Happy New Year
             Happy New Year
              Happy New Year
               Happy New Year
                Happy New Year
               Happy New Year
              Happy New Year
             Happy New Year
            Happy New Year
           Happy New Year
          Happy New Year
         Happy New Year
         Happy New Yea
          Happy New Y
           Happy New
            Happy N
             Happy
              Hap
               H

EDIT: Try this:
Code:
awk -vW=30 '-vL=Happy New Year' 'BEGIN{for(i=k=1;i>=1;i+=k) {while(length(L)<W)L=L" "L;printf("%*.*s\n",(W/2)+i,i*2-1,L);if(i>=W/2)k=-1}}'

These 2 Users Gave Thanks to RudiC For This Post:
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Diamond operator in Until Statement (perl)

Hello: I have the following perl script which is giving me trouble inside the second elsif statement. The purpose of the script is to go through a file and print out only those lines which contain pertinent information. The tricky part came when I realized that certain items actually spanned... (5 Replies)
Discussion started by: erichpowell
5 Replies

2. Shell Programming and Scripting

Fun with awk

uggc://ra.jvxvcrqvn.bet/jvxv/EBG13 #!/usr/bin/awk -f BEGIN { for (n=0;n<26;n++) { x=sprintf("%c",n+65); y=sprintf("%c",(n+13)%26+65) r=y; r=tolower(y) } } { b = "" for (n=1; x=substr($0,n,1); n++) b = b ((y=r)?y:x) print b } ... (0 Replies)
Discussion started by: colemar
0 Replies

3. Shell Programming and Scripting

More fun with awk

#!/usr/bin/ksh ls -l $@ | awk ' /^-/ { l = 5*log($5) h = sprintf("%7d %-72s",$5,$8) print "\x1B ls command with histogram of file sizes. The histogram scale is logaritmic, to avoid very short bars for smaller files or very long bars for bigger files. Screenshot: (4 Replies)
Discussion started by: colemar
4 Replies

4. Shell Programming and Scripting

Perl Diamond Operator

I know that when using 'while (<FILE>) {}', Perl reads only one line of the file at one time, and store it in '$_'. Can I change some parameters so that 'while (<>) {}' can read more than one lines, like 2 or 5 lines at one time? Thanks for the help! (1 Reply)
Discussion started by: zx1106
1 Replies

5. UNIX for Dummies Questions & Answers

fun and easy awk question

I have a file called mytitles.txt containing a list of book titles I have a second file called abfile.txt containing a list of book titles (in the 3rd field) and it has author info and copyright year info as well.. I want to search mytitles.txt for a match in the 3rd field of abfiles.txt, and... (2 Replies)
Discussion started by: glev2005
2 Replies

6. What is on Your Mind?

Place your bets! - Ryder Cup 2012 (Golf)

Who will win the 2012 Ryder Cup. Europe vs USA There is an open event in the Event Prediction Forum. The event closes on 27th Sep 2012. 2012 Ryder Cup - Wikipedia, the free encyclopedia (0 Replies)
Discussion started by: ni2
0 Replies

7. Shell Programming and Scripting

To print diamond asterisk pattern based on inputs

I have to print the number of stars that increases on each line from the minimum number until it reaches the maximum number, and then decreases until it goes back to the minimum number. After printing out the lines of stars, it should also print the total number of stars printed. I have tried... (13 Replies)
Discussion started by: rohit_shinez
13 Replies
SBUS(4) 						   BSD Kernel Interfaces Manual 						   SBUS(4)

NAME
SBus -- introduction to machine-independent SBus bus support and drivers SYNOPSIS
sbus* at mainbus? sbus* at iommu? sbus* at xbox? These SBus attachments are specific to the NetBSD/sparc and NetBSD/sparc64 ports. DESCRIPTION
SBus is a I/O interconnect bus mostly found in SPARC workstations and small to medium server class systems. It supports both on-board peripherals and extension boards. The SBus specifications define the bus protocol as well as the electrical and mechanical properties of the extension slots. HARDWARE
NetBSD includes machine-independent SBus drivers, sorted by device type and driver name: SCSI interfaces esp NCR53c94 and compatible SCSI interfaces. isp Qlogic SCSI interfaces. Network interfaces le Lance 7990 series Ethernet interfaces. hme ``Happy Meal'' Ethernet interfaces. en Midway-based Efficient Networks Inc. and Adaptec ATM interfaces. be ``Big Mac'' Ethernet board. qe Quad Ethernet Controller board. Bridges xbox an Sbus expansion box. Graphics devices bwtwo framebuffer device. cgthree framebuffer device. cgsix framebuffer device. pnozz framebuffer device. tcx framebuffer device. zx framebuffer device. Audio devices audiocs CS4231 codec. Serial interfaces magma Magma Serial/Parallel combo device. Floppy interfaces fdc Floppy disk controller SEE ALSO
audiocs(4), be(4), bwtwo(4), cgsix(4), cgthree(4), en(4), esp(4), fdc(4), hme(4), intro(4), isp(4), le(4), magma(4), pnozz(4), qe(4), tcx(4), xbox(4), zx(4) HISTORY
The machine-independent SBus subsystem appeared in NetBSD 1.3. BSD
January 7, 2009 BSD
All times are GMT -4. The time now is 03:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy