【问题标题】:mv: cannot stat ‘2001010000\r’: No such file or directory [duplicate]mv:无法统计'2001010000 \ r':没有这样的文件或目录[重复]
【发布时间】:2020-06-01 09:24:52
【问题描述】:

我有一个文件 abc.out,我需要读取它并将内容导出到命名管道。我的shell脚本如下:

#!/bin/ksh -x

cd /home/robert/

if [[ -s abc.out ]]; then
  sleep 2
  for i in `cat abc.out`
  do
    mv -f $i ./abc_archive/x$i
    print `pwd`/abc_archive/x$i > /home/robert/pipe_abc
    sleep 1
  done
fi

abc.out 文件内容如下:

2001010000
2001010001
2001010002

但是当我用命令sh abc.spt运行脚本时,错误提示如下:

mv: cannot stat ‘2001010000\r’: No such file or directory

如何解决这个问题,非常感谢!

【问题讨论】:

  • 从输入文件中删除干扰\r 符号,即CR
  • 您的文件abc.out 有dos 行结尾。您应该阅读带有for i in cat 的行,有how to read a file line by line in bash 但同样适用于ksh。
  • 我修改了脚本如下: if [[ -s bcfin.out ]];然后睡眠 2 而 IFS= 读取 -r 行 || [[ -n "$line" ]]; do mv -f $line ./bcf_archive/x$line print pwd/bcf_archive/x$line > /home/cdr/robert/test_awsget_oracle/pipe_dvf sleep 1 done

标签: linux shell pipe


【解决方案1】:

一种选择是通过 sed 或 tr 管道输出,以删除回车: sed -e 's/[\r\n]//g' 或者 tr -d '\r' 如果你只想删除 \r

【讨论】:

    猜你喜欢
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 2021-12-21
    • 1970-01-01
    相关资源
    最近更新 更多