0

我有很多文件,例如ABC_Timestamp.txtRAM_Timestamp.txt这里的时间戳每次都会不同。我想将此文件复制到其他目录,但在复制时我想在文件末尾附加一个字符串,因此格式为ABC_Timestamp.txt.OKand RAM_Timestamp.txt.OK。如何在动态文件中附加字符串。请建议。

4

4 回答 4

1

在命令行上执行此操作。

ls -1|awk '/ABC_.*\.txt/||/RAM_.*\.txt/
          {old=$0;
           new="/new_dir/"old".OK";
           system("cp "old" "new); }'

取自这里

于 2013-09-10T07:22:05.820 回答
1

我的2便士:

(cat file.txt; echo "append a line"; date +"perhaps with a timestamp: %T") > file.txt.OK

或更完整的文件名:

 while sleep 3;
 do
    for a in ABC RAM
    do
        (echo "appending one string at the end of the file" | cat ${a}_Timestamp.txt -) > ${a}_Timestamp.txt.OK
    done
 done
于 2013-09-10T07:00:51.477 回答
0

你可以说:

for i in *.txt; do cp "${i}" targetdirectory/"${i}".OK ; done

或者

for i in ABC_*.txt RAM_*.txt; do cp "${i}" targetdirectory/"${i}".OK ; done
于 2013-09-10T07:00:54.367 回答
-1

如何先将文件名转储到另一个文件中,然后一个一个地移动文件。

  find . -name "*.txt" >fileNames


  while read line
  do
  newName="${line}appendText"
  echo $newName
  cp $line $newName
  done < fileNames
于 2013-09-10T07:32:50.393 回答