Quantcast
Viewing all articles
Browse latest Browse all 5

Answer by Stéphane Chazelas for Link variables between two text files

With zsh and with libnumbertext-tools's spellout on Debian:

#! /bin/zsh -colors=(${(f)"$(<log1.txt)"})adjectives=(${(f)"$(head -n ${#colors} <log2.txt)"})/usr/lib/libnumbertext/spellout -l /usr/share/libnumbertext/en \  -p ordinal 1-$#colors |for color adjective in ${colors:^^adjectives}; do  read num &&  print -r The $num color $color is $adjectivedone

(note that it's US-English. For instance, for 101, you get one hundred first instead of one hundred and first)

If you can't install zsh or any software that spells out numbers but have a list of English ordinals in a third log3.txt file, you could do in most shells including bash (Bourne-like, rc-like, fish at least):

#! /bin/sh -awk '  BEGIN {while ((getline a < "log2.txt") > 0) adjective[na++] = a}  {    if ((getline num < "log3.txt") <= 0) num = NR "th"    print "The "num" color "$0" is "adjective[(NR-1)%na]  }' log1.txt

(falling back to <digits>th if we run out of English numbers).


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>