如何编写一个脚本,在命令行获取2个文件从另一个写入并写入另一个[关闭]


-1

编写一个bash文件,在命令行中获取两个文件,从中读取第一个文件并写入下一个文件,例如./file.sh input_file.txt output_file.txt

    #!/bin/bash

     read file1 file2

     exec 400<> file1.txt
     while read line1 <&400           #use towns.txt file discripter to inte$
         do
         {
            full_line=$line1
            echo $full_line >>file2.txt           
         }
         done
     exec 400>&-

你的问题弗林特是什么?这似乎没有问题,似乎是一个答案,很可能会因为不清楚而被关闭。
Paul

Answers:


0

尝试使用 位置参数 。在这种情况下,您将使用:

file1="$1" #input file
file2="$2" #output file

然后参考 file1file2 在整个脚本中。当您运行脚本时 file1 是第一个参数和 file2 是第二个,像这样:

./myscript.sh input.txt output.txt


但我遇到了一个问题,file1无法写入file2`exec 400&lt;&gt; file1.txt同时读取line1&lt;&amp; 400 do {full_line = $ line1 echo $ full_line&gt;&gt; file2.txt} done exec 400&gt;&amp; -`
Flint
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.