Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.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 为什么我的代码会对当前行造成冲击?_Bash_Append - Fatal编程技术网

Bash 为什么我的代码会对当前行造成冲击?

Bash 为什么我的代码会对当前行造成冲击?,bash,append,Bash,Append,我正在尝试构建一个包含ipv4地址列表的国家的csv。 我一直在输出文件中重击IP #!/bin/bash cat ipv4list.txt | while read ip ;do echo -n "$ip", >> outputfile whois -r "$ip">temp.txt cat temp.txt | grep -i country >> outputfile done cat ipv4list.txt 1.1.1.1 2.2.2.2

我正在尝试构建一个包含ipv4地址列表的国家的csv。 我一直在输出文件中重击IP

#!/bin/bash
cat ipv4list.txt | while read ip ;do
  echo -n "$ip", >> outputfile
  whois -r "$ip">temp.txt
  cat temp.txt | grep -i country >> outputfile
done
cat ipv4list.txt

1.1.1.1
2.2.2.2
我想读的是outputfile

1.1.1.1,country:    AU
2.2.2.2,country:    US
但我得到的输出文件如下

,country:    AU
,country:    US

echo语句需要引用ip变量:

echo -n "$ip", >> outputfile

此外,重击表示输入文件可能使用窗口新行(\r\n)。用编辑器检查输出文件,或者在这里检查hextump有点超出框。伙计们,请善待我

pop.ed:-

1d
wq

whois.sh:-

#!/bin/sh -x

init() {
    cp ipv4list ipv4stack
}

next() {
    [[ -s ipv4stack ]] && main
}

main() {
    ip=$(echo "1p" | ed -s ipv4stack.txt)
    wic=$(whois -r "${ip}")
    echo "${ip},${wic}" >> outputfile
    ed -s ipv4stack.txt < pop.ed
    next
}

init
next
pop.ed:-
1d
wq
whois.sh:-
#!/bin/sh-x
init(){
cp IPV4列表IPV4堆栈
}
下一个(){
[[-s ipv4stack]]&&main
}
main(){
ip=$(echo“1p”| ed-s ipv4stack.txt)
wic=$(whois-r“${ip}”)
echo“${ip},${wic}”>>输出文件
ed-s ipv4stack.txt

遗憾的是,如今大多数发行版中显然也没有默认安装Ed;因此,如果您想使用它,您可能需要安装它。

请将示例输入(无描述、无图像、无链接)和您希望的该示例输入输出添加到您的问题(无注释)。尝试在注释中添加代码。不是我的日子。下一行输入为1.1.1.1,后接2.2.2.2。在开始下一行之前,输出需要为1.1.1.1,国家:AU。我实际得到的输出是,country:AUDid您是否尝试使用
xxd
od-cx
验证
outputfile
?可能
whois
在其输出中生成回车符。此外,您不会将ip地址写入输出文件,而是写入文本字符串
ip
。最后,您的最后两行可以简化为
whois-r$ip | grep-i country>>outputfile
.Ah thx。令人惊叹的。xxd显示IP毕竟在那里。猫看不见。查看十六进制,其中有新行,0x0a可能是罪魁祸首。在重新创建上面的代码时输入错误。我的代码中有一个$。不过还是有好消息。我会编辑的,谢谢。十六进制显示IP毕竟在那里。需要过滤掉一些奇怪的十六进制字符。