【问题标题】:shell scripting - Write in a fileshell 脚本 - 写入文件
【发布时间】:2020-01-27 18:29:19
【问题描述】:

Shell 脚本:我有以下输入文件 file1的内容

-bash-4.2$ cat file1
sample.1.17.10.tar
test.1.17.10.tar
work.1.17.1.0.tar

需要得到如下输出

From : > cat file2

    sample
    test
    work

From :>cat file3

1.17.10
1.17.10
1.17.10

它应该通过剥离提到的名称和值来生成两个文件

【问题讨论】:

  • 您是否希望将以上三个文件输出到一个文件中?或者您正在尝试将所有 tar 文件的内容连接到文件中,或者您只需要文件名?
  • 我的输入是 file1 -> 输出应该在 file2 和 file3 中
  • 我只需要文件名。不是内容
  • 你只需要名字吗?你已经有了它们,它们肯定是file2file3
  • 你不想从work.1.17.1.0.tar 生成1.17.1.0 吗?

标签: shell


【解决方案1】:

Cut and Rev 按照示例使用。

$ cat test.test
sample.1.17.10.tar
test.1.17.10.tar
work.1.17.1.0.tar

# For Version
$cat test.test | rev | cut -d"." -f2-  | rev | cut -d"." -f2-  > file1
$ $ cat file1
1.17.10
1.17.10
1.17.1.0

# For Filename
$ $ cat test.test | cut -d'.' -f 1 > file2
$ cat file2 
sample
test
work

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多