Cshell 上的脚本

发布于 2024-09-03 09:34:28 字数 271 浏览 2 评论 0原文

我遇到了一些问题,我在文件中有数据列表:

053-37878 03828008 Moskovitch James 500
052-34363 01234567 Mendelson Kippi 450
053-32322 03828008 Jameson Shula 350
054-39238 03333333 Merden Moshe 300

是否可以在同一个文件中重写此列表(不使用临时文件),但没有最后一个数字,提前感谢任何帮助(我说的是 C-外壳脚本)

I've got some problem, I have list of data in the file:

053-37878 03828008 Moskovitch James 500
052-34363 01234567 Mendelson Kippi 450
053-32322 03828008 Jameson Shula 350
054-39238 03333333 Merden Moshe 300

is it possible rewrite this list in the same file (without using temporary file) but without last number thanks in advance for any help (I'm talking about C-Shell scripts)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剧终人散尽 2024-09-10 09:34:28
  1. 为什么需要避免临时文件?

    cut -d " " -f 1,2,3 myfile >我的文件2; mv myfile2 我的文件
    
  2. 您还可以轻松地使用 Perl 的 -i 开关就地编辑文件。它仍然会在幕后创建一个临时文件,IIRC。

  3. 如果你需要这个来做作业,使用 Perl 将文件读入内存(File::Slurp),使用正则表达式或类似的东西截掉最后一个字段;并使用另一个 File::Slurp 从整个存储的数据覆盖该文件

  1. Why do you need to avoid temporary files?

    cut -d " " -f 1,2,3 myfile > myfile2; mv myfile2 myfile
    
  2. You can also easily use Perl's -i switch to edit the file in place. It still creates a temp file under the covers, IIRC.

  3. If you need this for homework, use Perl to read the file into memory (File::Slurp), chop off last field using regex or somesuch; and write over the file from entire stored data using another File::Slurp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文