基本上,我试图从三个包含独特信息的文本文件中读取信息。
文本文件的设置方式是这样的:
textA.txt
----------------
something.awesome.com
something2.awesome.com
something3.awesome.com
...
textB.txt
----------------
123
456
789
...
textC.txt
----------------
12.345.678.909
87.65.432.1
102.254.326.12
....
现在当我输出它时它看起来像这样
something.awesome.com : 123 : 12.345.678.909
something2.awesome.com : 456 : 87.65.432.1
something3.awesome.com : 789 : 102.254.326.12
我现在尝试的代码是这样的:
for each in `cat site.txt` ; do
site=`echo $each | cut -f1`
for line in `cat port.txt` ; do
port=`echo $line | cut -f1`
for this in `cat ip.txt` ; do
connect=`echo $this | cut -f1`
echo "$site : $port : $connect"
done
done
done
我得到的结果大错特错,不是我想要的。我不知道如何解决这个问题。
我希望能够通过变量形式调用信息。
最佳答案
paste testA.txt testB.txt testC.txt | sed -e 's/\t/ : /g'
输出是:
something.awesome.com : 123 : 12.345.678.909 something2.awesome.com : 456 : 87.65.432.1 something3.awesome.com : 789 : 102.254.326.12
Edit: Here is a solution using pure bash
:
#!/bin/bash
exec 7<testA.txt
exec 8<testB.txt
exec 9<testC.txt
while true
do
read site <&7
read port <&8
read connect <&9
[ -z "$site" ] && break
echo "$site : $port : $connect"
done
exec 7>&-
exec 8>&-
exec 9>&-
关于linux - 从文本文件中检索信息。 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11561720/