Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.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
Linux 在文件中的变量后写入新行_Linux_Bash_Awk_Scripting_Grep - Fatal编程技术网

Linux 在文件中的变量后写入新行

Linux 在文件中的变量后写入新行,linux,bash,awk,scripting,grep,Linux,Bash,Awk,Scripting,Grep,我正在用bash编写一个脚本,并使用一个临时文件来存储我需要的一些数字。我收到一些grep的数字,并希望将其写入文件中 除最后一行外,每个数字后面都有新行 myparts=$(grep -f parts.txt number.log | awk -F'[][]' '{print $2}'| sort | uniq) echo -e $myparts+'\n' >> tempfile 这是我尝试过的,但没有成功 +不是shell中的字符串连接运算符 echo -e "$myp

我正在用bash编写一个脚本,并使用一个临时文件来存储我需要的一些数字。我收到一些grep的数字,并希望将其写入文件中 除最后一行外,每个数字后面都有新行

myparts=$(grep -f parts.txt number.log | awk -F'[][]' '{print $2}'| sort | uniq)
    echo -e $myparts+'\n' >> tempfile

这是我尝试过的,但没有成功

+
不是shell中的字符串连接运算符

echo -e "$myparts\n" >> tempfile
@acezcoder
echo“$myparts”
应该可以让您自己在一行中找到每个数字。如果无法引用,
$myparts
中的内部空白将丢失。