Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File Unix-文件编辑保存_File_Unix_Save - Fatal编程技术网

File Unix-文件编辑保存

File Unix-文件编辑保存,file,unix,save,File,Unix,Save,我正在完成我的作业,以下是说明。我以为我几乎完成了,但我不断收到一个错误,说我没有更改文件中的任何内容或没有保存它。不是真的在寻找整个问题的解决方案,而是我的问题的指南。感谢您的帮助 Create a new directory, ~/UnixCourse/editingAsst. Copy into that directory the file ~cs252/Assignments/editingAsst/mtswe10.txt Use one of the thre

我正在完成我的作业,以下是说明。我以为我几乎完成了,但我不断收到一个错误,说我没有更改文件中的任何内容或没有保存它。不是真的在寻找整个问题的解决方案,而是我的问题的指南。感谢您的帮助

  Create a new directory, ~/UnixCourse/editingAsst.

    Copy into that directory the file ~cs252/Assignments/editingAsst/mtswe10.txt

    Use one of the three editors discussed in this language to edit the file ~/UnixCourse/editingAsst/mtswe10.txt

    In line 597, change the semicolon (;) to a period, and capitalize the first letter of the word immediately after it.

    Somewhere within that file is the string “man men”. Change it to “many men”.

    Replace all occurrences in the file of the word “elephant” by the word “wombat” (replacing the case variant “Elephant” by “Wombat”).

    Save your changed file, and exit the editor. (Do not rename the file when you save it. It should still be named mtswe10.txt.)

    Use the diff and grep commands to check your changes and make sure that you have made all the changes that you were supposed to and no others.

    Give the command

    ~cs252/bin/editingAsst
以下是我的解决方案:

mkdir ~/UnixCourse/editingAsst
cp ~cs252/Assignments/editingAsst/mtswe10.txt ~/UnixCourse/editingAsst
sed -i '597 s/\([;]\)/./' ~/UnixCourse/editingAsst/mtswe10.txt
sed -i '' '597 s/(\. [a-z])/\U&\E/' ~/UnixCourse/editingAss/mtswe10.txt
sed -i '' ' s/man men/many men/' ~/UnixCourse/editingAsst/mtswe10.txt
sed -i '' ' s/Elephant/Wombat/g' ~/UnixCourse/editingAsst/mtswe10.txt
sed -i '' ' s/elephant/wombat/g' ~/UnixCourse/editingAsst/mtswe10.txt

所以直到最后一步我才发现任何错误,当我试图保存作业时,它会给出错误。同样使用
sed-i''334 s/(\[a-z])/\U&\E/'~/UnixCourse/editingAss/mtswe10.txt
会发出警告,但它确实接受


提前谢谢

我认为,问题在于除了第一个
sed
命令之外,您在所有命令上都有额外的
'
参数
sed
将第一个lone参数视为脚本,将第二个lone参数视为文件名。因此,第二个命令有一个空脚本和一个它无法处理的复杂文件名。如果去掉这些额外的参数,它应该可以工作

mkdir ~/UnixCourse/editingAsst
cp ~cs252/Assignments/editingAsst/mtswe10.txt ~/UnixCourse/editingAsst
sed -i '597 s/\([;]\)/./' ~/UnixCourse/editingAsst/mtswe10.txt
sed -i '597 s/(\. [a-z])/\U&\E/' ~/UnixCourse/editingAss/mtswe10.txt
sed -i 's/you are conquered/ye are conquered/' ~/UnixCourse/editingAsst/mtswe10.txt
sed -i 's/Elephant/Wombat/g' ~/UnixCourse/editingAsst/mtswe10.txt
sed -i 's/elephant/wombat/g' ~/UnixCourse/editingAsst/mtswe10.txt
您可以在管道中执行所有这些操作,而无需使用
-i

cp ~cs252/Assignments/editingAsst/mtswe10.txt ~/UnixCourse/editingAsst
sed '597 s/\([;]\)/./' ~/UnixCourse/editingAsst/mtswe10.txt |
   sed -597 s/(\. [a-z])/\U&\E/' |
   sed 's/you are conquered/ye are conquered/' |
   sed 's/Elephant/Wombat/g' |
   sed 's/elephant/wombat/g' > tmp.txt
mv tmp.txt ~/UnixCourse/editingAsst/mtswe10.txt

我明白你的意思,谢谢你给我看这个。但是,我不确定该使用什么命令:“保存更改的文件,并退出编辑器。(保存文件时不要重命名该文件。它仍应命名为mtswe10.txt。)”出于某种原因,您建议使用wihtout的部分-我不起作用,但第一个参数较少的部分直到最后一步才起作用。我知道您正在将文件移动到tmp.txt,并将其移动到mtswe10.txt,但该命令给了我错误。嗯,“退出编辑器”提示听起来好像他们希望您使用
vi
或某个交互式编辑器
sed
每次运行时都保存文件。你得到了什么错误?所以我用sed-I运行了所有命令,没有错误。在我使用大象/袋熊完成最后一步后,我运行了提供的代码:~cs252/bin/editingAsst,错误是:您似乎没有更改第597行。(在退出编辑器之前是否保存了更改?)。是否有一个特定的sed-i命令来保存文件而不重命名它?谢谢你的帮助!下面是我所做的,我从mkdir和cp开始,然后是vi代码开始编辑文本。我用过吗?man-men找到它,我用许多人替换它,并向下滚动到第597行,找到插入分号并替换为句号的分号。还使用“:%s/elephant/wombat/gc”替换它,然后我保存了文件并退出。它成功了,谢谢你在整个过程中的帮助!