我有一个名为 abd 的文本文件,如下所示。
48878 128.206.6.136
34782 128.206.6.137
12817 23.234.22.106
Run Code Online (Sandbox Code Playgroud)
我只想从文本中提取 IP 地址并将其存储在变量中并用于其他目的。
我试过这个。
for line in `cat abd`
do
ip=`grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' $line`
echo $ip
done
Run Code Online (Sandbox Code Playgroud)
我收到如下错误
grep: 34782: No such file or directory
grep: 128.206.6.137: No such file or directory
grep: 12817: No such file or directory
grep: 23.234.22.106: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我不知道这里出了什么问题。任何帮助,将不胜感激。
我有一个名为 sample.text 的文本文件,它看起来像这样
Continent Lat/Lon: 46.07305 / -100.546
Country Lat/Lon: 38 / -98
City Lat/Lon:(37.3845) / (-122.0881)
Run Code Online (Sandbox Code Playgroud)
我想处理此文本以在不使用临时文件的情况下获得如下输出
Continent Lat/Lon: 46.07305 / -100.546
Country Lat/Lon: 38 / -98
City Latitude: (37.3845)
City Longitude: (-122.0881)
Run Code Online (Sandbox Code Playgroud)
我无法控制纬度/经度的值。
我已经使用 2 个 awk 脚本完成了这项工作
BEGIN { FS=":"} {print $2} | BEGIN { FS="/"} {printf "City Latitude:%s\nCity Longitude:%s\n",$1,$2}
Run Code Online (Sandbox Code Playgroud)
因为我想写原始文件,有什么方法可以使用
sed -i
Run Code Online (Sandbox Code Playgroud)
感谢所有输入。
我有这样的文本文件。
2015-11-24 12:59:37.112 128.206.6.136 source
2014-11-24 12:59:36.920 8.8.8.8 source
2014-11-24 14:59:38.112 23.234.22.106 destination
2014-11-24 13:59:37.113 23.234.22.106 source
2014-11-24 12:59:29.047 74.125.198.141 source
2014-12-25 12:59:36.920 74.125.198.148 destination
Run Code Online (Sandbox Code Playgroud)
如果特定的 Ip 地址被标记为源和目标,那么我想将该 Ip 标记为both。在这种情况下,IP 23.234.22.106 既是源也是目标。所以,我想把它标记为both。
我想要的输出应该是这样的
2015-11-24 12:59:37.112 128.206.6.136 source
2014-11-24 12:59:36.920 8.8.8.8 source
2014-11-24 14:59:38.112 23.234.22.106 both
2014-11-24 12:59:29.047 74.125.198.141 source
2014-12-25 12:59:36.920 74.125.198.148 destination
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的。
cat input.txt | awk '{print $3}' | sort | uniq | while read line
do
grep $line input.txt | sort -r -k1 …
Run Code Online (Sandbox Code Playgroud)