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
HME(4)							   BSD Kernel Interfaces Manual 						    HME(4)

NAME
hme -- Sun Microelectronics STP2002-STQ Ethernet interfaces device driver SYNOPSIS
To compile this driver into the kernel, place the following lines in your kernel configuration file: device miibus device hme Alternatively, to load the driver as a module at boot time, place the following line in loader.conf(5): if_hme_load="YES" DESCRIPTION
The hme driver supports Sun Microelectronics STP2002-STQ ``Happy Meal Ethernet'' Fast Ethernet interfaces. All controllers supported by the hme driver have TCP checksum offload capability for both receive and transmit, support for the reception and transmission of extended frames for vlan(4) and a 128-bit multicast hash filter. HARDWARE
The hme driver supports the on-board Ethernet interfaces of many Sun UltraSPARC workstation and server models. Cards supported by the hme driver include: o Sun PCI SunSwift Adapter (``SUNW,hme'') o Sun SBus SunSwift Adapter (``hme'' and ``SUNW,hme'') o Sun PCI Sun100BaseT Adapter 2.0 (``SUNW,hme'') o Sun SBus Sun100BaseT 2.0 (``SUNW,hme'') o Sun PCI Quad FastEthernet Controller (``SUNW,qfe'') o Sun SBus Quad FastEthernet Controller (``SUNW,qfe'') NOTES
On sparc64 the hme driver respects the local-mac-address? system configuration variable which can be set in the Open Firmware boot monitor using the setenv command or by eeprom(8). If set to ``false'' (the default), the hme driver will use the system's default MAC address for all of its devices. If set to ``true'', the unique MAC address of each interface is used if present rather than the system's default MAC address. Supported interfaces having their own MAC address include on-board versions on boards equipped with more than one Ethernet interface and all add-on cards except the single-port SBus versions. SEE ALSO
altq(4), intro(4), miibus(4), netintro(4), vlan(4), eeprom(8), ifconfig(8) Sun Microelectronics, STP2002QFP Fast Ethernet, Parallel Port, SCSI (FEPS) User's Guide, http://mediacast.sun.com/users/Barton808/media/STP2002QFP-FEPs_UG.pdf, April 1996. HISTORY
The hme driver first appeared in NetBSD 1.5. The first FreeBSD version to include it was FreeBSD 5.0. AUTHORS
The hme driver was written by Paul Kranenburg <pk@NetBSD.org>. BSD
June 14, 2009 BSD
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy