Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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
在bash linux中复制一行并粘贴5次_Linux_Bash_Copy_Line_Paste - Fatal编程技术网

在bash linux中复制一行并粘贴5次

在bash linux中复制一行并粘贴5次,linux,bash,copy,line,paste,Linux,Bash,Copy,Line,Paste,在bash中的复制行中需要帮助 **Input: (input.txt)** http://localhost.com/123/test.png http://localhost.com/456/test.png 所以这两行应该在新文件中粘贴5次。。。 所以我想得到如下输出 **Output: (output.txt)** http://localhost.com/123/test.png http://localhost.com/123/test.png http://localhost

在bash中的复制行中需要帮助

**Input: (input.txt)**

http://localhost.com/123/test.png
http://localhost.com/456/test.png
所以这两行应该在新文件中粘贴5次。。。 所以我想得到如下输出

**Output: (output.txt)**

http://localhost.com/123/test.png
http://localhost.com/123/test.png
http://localhost.com/123/test.png
http://localhost.com/123/test.png
http://localhost.com/123/test.png
http://localhost.com/456/test.png
http://localhost.com/456/test.png
http://localhost.com/456/test.png
http://localhost.com/456/test.png
http://localhost.com/456/test.png
那么,如何才能做到这一点呢? 有人能给shell脚本使这成为可能吗

谢谢

试试这个:

awk '{for (i=0;i<5;i++) print $NF }' input.txt
您可以使用以下选项:

 sed 'p;p;p;p' input.txt > output.txt

您也可以尝试下面的perl命令

perl -ne 'print "$_"x5' file

$\是Perl中的一个特殊变量,它像awk中的$0 do一样存储当前行。因此$\u x5将当前行重复5次。

以下是循环的经典方式:

while read line; do
  for i in {1..5}; do
    echo "before_text${line}after_text"
  done
done < input.txt

@almas如果您将$NF更改为$0会更好,因为如果一行包含spaces.thanx作为答案,那么您的命令将不起作用,有没有办法在输出文件中获得不同的后缀..ex::localhost.com/123/a localhost.com/123/b如果您知道要迭代的内容,请将其放在,并使用它索引到数组中。你可以从Thanx获得更多链接@avinash的答案