AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-14962

Dingo's questions

Martin Hope
Dingo
Asked: 2022-06-13 02:34:00 +0800 CST

按照给定规则缩进文本行

  • 2

我想知道如何按照自定义规则递归地缩进越来越多的诗行。例如

假设我们有:

OF Mans First Disobedience, and the Fruit
Of that Forbidden Tree, whose mortal tast
Brought Death into the World, and all our woe,
With loss of Eden, till one greater Man
Restore us, and regain the blissful Seat,
Sing Heav'nly Muse, that on the secret top
Of Oreb, or of Sinai, didst inspire
That Shepherd, who first taught the chosen Seed,
In the Beginning how the Heav'ns and Earth
Rose out of Chaos: Or if Sion Hill
Delight thee more, and Siloa's Brook that flow'd
Fast by the Oracle of God; I thence
Invoke thy aid to my adventrous Song,
That with no middle flight intends to soar
Above th' Aonian Mount, while it pursues
Things unattempted yet in Prose or Rhime.
And chiefly Thou O Spirit, that dost prefer
Before all Temples th' upright heart and pure,
Instruct me, for Thou know'st; Thou from the first
Wast present, and with mighty wings outspread.

我们想递归缩进它,在第一行之后的任何三行添加3个空格,以这种方式

OF Mans First Disobedience, and the Fruit
   Of that Forbidden Tree, whose mortal tast
   Brought Death into the World, and all our woe,
   With loss of Eden, till one greater Man
Restore us, and regain the blissful Seat,
   Sing Heav'nly Muse, that on the secret top
   Of Oreb, or of Sinai, didst inspire
   That Shepherd, who first taught the chosen Seed,
In the Beginning how the Heav'ns and Earth
   Rose out of Chaos: Or if Sion Hill 
   Delight thee more, and Siloa's Brook that flow'd
   Fast by the Oracle of God; I thence
Invoke thy aid to my adventrous Song,
   That with no middle flight intends to soar
   Above th' Aonian Mount, while it pursues
   Things unattempted yet in Prose or Rhime.
And chiefly Thou O Spirit, that dost prefer
   Before all Temples th' upright heart and pure,
   Instruct me, for Thou know'st; Thou from the first
   Wast present, and with mighty wings outspread

实现这一目标的最简单方法是什么?

text-processing text-formatting
  • 2 个回答
  • 175 Views
Martin Hope
Dingo
Asked: 2022-05-15 09:03:27 +0800 CST

用 utf-8 功能替换 tr

  • 2

为了隔离一首诗的任何一行中的最后一个单词(列出所有押韵),我将几个代码片段放在一起获得这个

awk '{print $NF}' input.txt | tr 'A-Z' 'a-z'  | tr -sc 'a-z' '\n' | rev |  sort | uniq | sort -d | rev

将其应用于这样的诗歌:

Se a ciascun l'interno affanno
Si leggesse in fronte scritto
Quanti mai, che invidia fanno
Ci farebbero pietà! 

我明白了

fanno
affanno
scritto
piet

如您所见,“ pietà ”这个词没有重音字符。我想这取决于没有 tr UTF-8 功能。是否有任何替代 tr 能够在这一个班轮中执行相同的任务,但保留 UTF-8 重音字符?

text-processing unicode
  • 2 个回答
  • 276 Views
Martin Hope
Dingo
Asked: 2021-12-15 17:19:01 +0800 CST

用罗马数字给诗节编号

  • 3

我可以使用这样的罗马数字按顺序编号一首诗的任何节:

       
       Injurious love, why still to mar accord
       Between desires has been thy favourite feat?
       Why does it please thee so, perfidious lord,
       Two hearts should with a different measure beat?
       Thou wilt not let me take the certain ford,
       Dragging me where the stream is deep and fleet.
       Her I abandon who my love desires,
       While she who hates, respect and love inspires.
       
       Thou to Rinaldo show'st the damsel fair,
       While he seems hideous to that gentle dame;
       And he, who when the lady's pride and care,
       Paid back with deepest hate her amorous flame,
       Now pines, himself, the victim of despair,
       Scorned in his turn, and his reward the same.
       By the changed damsel in such sort abhorred,
       She would choose death before that hated lord.
       
       He to the Pagan cries: "Forego thy theft,
       And down, false felon, from that pilfer'd steed;
       I am not wont to let my own be reft.
       And he who seeks it dearly pays the deed.
       More -- I shall take from thee yon lovely weft;
       To leave thee such a prize were foul misdeed;
       And horse and maid, whose worth outstrips belief,
       Were ill, methinks, relinquished to a thief."
       
       "Thou liest," the haughty Saracen retorts,
       As proud, and burning with as fierce a flame,
       "A thief thyself, if Fame the truth reports:
       But let good deeds decide our dubious claim,
       With whom the steed or damsel fair assorts:
       Best proved by valiant deeds: though, for the dame,
       That nothing is so precious, I with thee
       (Search the wide world throughout) may well agree."
        

进入这个:罗马大写数字与最后一节对齐?

       Injurious love, why still to mar accord
       Between desires has been thy favourite feat?
       Why does it please thee so, perfidious lord,
       Two hearts should with a different measure beat?
       Thou wilt not let me take the certain ford,
       Dragging me where the stream is deep and fleet.
       Her I abandon who my love desires,
I      While she who hates, respect and love inspires.
       
       Thou to Rinaldo show'st the damsel fair,
       While he seems hideous to that gentle dame;
       And he, who when the lady's pride and care,
       Paid back with deepest hate her amorous flame,
       Now pines, himself, the victim of despair,
       Scorned in his turn, and his reward the same.
       By the changed damsel in such sort abhorred,
II     She would choose death before that hated lord.
       
       He to the Pagan cries: "Forego thy theft,
       And down, false felon, from that pilfer'd steed;
       I am not wont to let my own be reft.
       And he who seeks it dearly pays the deed.
       More -- I shall take from thee yon lovely weft;
       To leave thee such a prize were foul misdeed;
       And horse and maid, whose worth outstrips belief,
III    Were ill, methinks, relinquished to a thief."
       
       "Thou liest," the haughty Saracen retorts,
       As proud, and burning with as fierce a flame,
       "A thief thyself, if Fame the truth reports:
       But let good deeds decide our dubious claim,
       With whom the steed or damsel fair assorts:
       Best proved by valiant deeds: though, for the dame,
       That nothing is so precious, I with thee
IV     (Search the wide world throughout) may well agree."
        

我想知道是否有任何方法可以使用文本实用程序在 linux 中进行此操作。它可能不适合 awk,以罗马风格生成数字,但我已经在互联网上的某个地方找到了一个 bash 脚本来生成罗马数字

#/bin/bash
# roman.sh
#
#   Function
#
    num2roman() { # NUM
    # Returns NUM in roman letters
    #
        input=$1    # input num
        output=""   # Clear output string
        len=${#input}   # Initial length to count down
        
        roman_val() { # NUM one five ten
        # This sub does the basic 'roman' algorythm
        #
            N=$1
            one=$2
            five=$3
            ten=$4
            out=""
            
            case $N in
            0)  out+="" ;;
            [123])  while [[ $N -gt 0 ]]
                do  out+="$one"
                    N=$(($N-1))
                done
                ;;
            4)  out+="$one$five"    ;;
            5)  out+="$five"    ;;
            [678])  out+="$five"
                N=$(($N-5))
                while [[ $N -gt 0 ]]
                do  out+="$one"
                    N=$(($N-1))
                done
                ;;
            9)  while [[ $N -lt 10 ]]
                do  out+="$one"
                    N=$(($N+1))
                done
                out+="$ten"
                ;;
            esac
            echo $out
        }
        
        while [[ $len -gt 0  ]]
        do  # There are letters to add
            num=${input:0:1}
            # Do action according position
            case $len in
            1)  # 1
                output+="$(roman_val $num I V X)"
                ;;
            2)  # 10
                output+="$(roman_val $num X L C)"
                ;;
            3)  # 100
                output+="$(roman_val $num C D M)"
                ;;
            *)  # 1000+
                # 10'000 gets a line above, 100'000 gets a line on the left.. how to?
                num=${input:0:(-3)}
                while [[ $num -gt 0 ]]
                do  output+="M"
                    num=$(($num-1))
                done
                
                ;;
            esac
            input=${input:1} ; len=${#input}
        done
        echo $output
    }
#
#   Call it
#
    num2roman $1

我用这种语法调用:

 for N in `seq 1 10`;do ./roman.sh $N; done

谁的输出是:

I
II
III
IV
V
VI
VII
VIII
IX
X

因此,从另一个角度来看,这可能只是从生成的罗马数字列表中挑选任何项目,然后将其中任何一项与任何一节的最后一节对齐

text-processing text-formatting
  • 3 个回答
  • 282 Views
Martin Hope
Dingo
Asked: 2021-12-09 16:53:28 +0800 CST

任何文本实用程序或破解省略某些数字的诗行编号?

  • 0

我的目标是尝试查看 linux 中是否有常见的文本实用程序可以用来对诗歌的行数进行编号,如下所示:

OF Mans First Disobedience, and the Fruit
Of that Forbidden Tree, whose mortal tast
Brought Death into the World, and all our woe,
With loss of Eden, till one greater Man
Restore us, and regain the blissful Seat,
Sing Heav'nly Muse, that on the secret top
Of Oreb, or of Sinai, didst inspire
That Shepherd, who first taught the chosen Seed,
In the Beginning how the Heav'ns and Earth
Rose out of Chaos: or if Sion Hill
Delight thee more, and Siloa's brook that flow'd
Fast by the Oracle of God; I thence
Invoke thy aid to my adventrous Song,
That with no middle flight intends to soar
Above th' Aonian Mount, while it pursues
Things unattempted yet in Prose or Rhime.
And chiefly Thou, O Spirit, that dost prefer
Before all Temples th' upright heart and pure,
Instruct me, for Thou know'st; Thou from the first
Wast present, and with mighty wings outspread
Dove-like satst brooding on the vast Abyss
And mad'st it pregnant: What in me is dark
Illumin, what is low raise and support;
That to the highth of this great Argument
I may assert Eternal Providence,
And justifie the wayes of God to men.

获得这个:

        OF Mans First Disobedience, and the Fruit
        Of that Forbidden Tree, whose mortal tast
        Brought Death into the World, and all our woe,
     4  With loss of Eden, till one greater Man
        Restore us, and regain the blissful Seat,
        Sing Heav'nly Muse, that on the secret top
        Of Oreb, or of Sinai, didst inspire
     8  That Shepherd, who first taught the chosen Seed,
        In the Beginning how the Heav'ns and Earth
        Rose out of Chaos: or if Sion Hill
        Delight thee more, and Siloa's brook that flow'd
    12  Fast by the Oracle of God; I thence
        Invoke thy aid to my adventrous Song,
        That with no middle flight intends to soar
        Above th' Aonian Mount, while it pursues
    16  Things unattempted yet in Prose or Rhime.
        And chiefly Thou, O Spirit, that dost prefer
        Before all Temples th' upright heart and pure,
        Instruct me, for Thou know'st; Thou from the first
    20  Wast present, and with mighty wings outspread
        Dove-like satst brooding on the vast Abyss
        And mad'st it pregnant: What in me is dark
        Illumin, what is low raise and support;
    24  That to the highth of this great Argument
        I may assert Eternal Providence,
        And justifie the wayes of God to men.

可以,awk,也可以用这种方式缩进行

          OF Mans First Disobedience, and the Fruit
        Of that Forbidden Tree, whose mortal tast
          Brought Death into the World, and all our woe,
     4  With loss of Eden, till one greater Man
          Restore us, and regain the blissful Seat,
        Sing Heav'nly Muse, that on the secret top
          Of Oreb, or of Sinai, didst inspire
     8  That Shepherd, who first taught the chosen Seed,

还有这样的吗?

        OF Mans First Disobedience, and the Fruit
          Of that Forbidden Tree, whose mortal tast
        Brought Death into the World, and all our woe,
     4    With loss of Eden, till one greater Man
        Restore us, and regain the blissful Seat,
          Sing Heav'nly Muse, that on the secret top
        Of Oreb, or of Sinai, didst inspire
     8    That Shepherd, who first taught the chosen Seed,
utilities text
  • 2 个回答
  • 291 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve