dongyong3554
dongyong3554
2016-04-04 07:48

使用sed从Windows中的文本文件中删除第一行

已采纳

I am working on PHP file and want to delete the first line from a text file.

Here is my code:

shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c \"sed '1d' $text_files_path/diffFile.txt\"");
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c 'sed '1d' $text_files_path/diffFile.txt'");
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c 'tail -n +2 $text_files_path/diffFile.txt'");
shell_exec("C:\\cygwin64\\bin\\bash.exe --login -c \"tail -n +2 '$text_files_path/diffFile.txt'\"");

But, nothing works!

Any idea please?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doujiao3072 doujiao3072 5年前

    Your variable should be double-quoted to allow shell parameter expansion.

    Try this :

    shell_exec('C:\\cygwin64\\bin\\bash.exe --login -c "sed -i \"1d\" "$text_files_path"/diffFile.txt"');
    

    Note : I added the -i option that edit the file in place.

    点赞 评论 复制链接分享