【问题标题】:Do a split on Carriage return and create an array in ksh在回车上进行拆分并在 ksh 中创建一个数组
【发布时间】:2011-11-16 16:53:40
【问题描述】:

我想根据回车进行拆分,然后创建一个数组。

process.txt

siebmtshm 30933160 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_30933160   
siebmtshm 31064248 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_28508402

数组的输出应该是:

Array[0] = siebmtshm 30933160 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_30933160   
Array[1] = siebmtshm 31064248 /app/cis/u01/sia80/siebsrvr/temp/SIEBEL_28508402

【问题讨论】:

  • “非常感谢您快速回复。”。这个论坛是针对编程问题的。它不是免费赠品咨询。向我们展示您尝试过的代码。那么也许我们可以提供帮助。祝你好运。

标签: shell unix scripting ksh


【解决方案1】:

这非常简单,因为从技术上讲,您的 process.txt 文件已经被拆分了。

您只需要逐行读取文件,如下所示:

let tempInt=0
while read file
do
  Array[$tempInt]=$file
  let tempInt=$tempInt+1
done<process.txt

在那里添加了一个计数器来跟踪您在数组中的索引。我在生产工作中做了很多次,没有失败。请注意,请确保您使用 BASH 作为您的解释器。您不希望卡在旧版 KSH 的 4096 字节限制中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 2019-05-13
    • 2018-02-21
    • 2017-09-05
    相关资源
    最近更新 更多