从文本文件中检索信息.Linux的

blo*_*m17 0 unix linux bash shell scripting

基本上我试图从三个文本文件中读取信息,其中包含唯一信息.

文本文件的设置方式如下:

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
....
Run Code Online (Sandbox Code Playgroud)

现在,当我输出类似这样的东西时它看起来像什么

something.awesome.com : 123 : 12.345.678.909
something2.awesome.com : 456 : 87.65.432.1
something3.awesome.com : 789 : 102.254.326.12
Run Code Online (Sandbox Code Playgroud)

我现在尝试的代码是这样的:

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
Run Code Online (Sandbox Code Playgroud)

我得到的结果只是疯狂的错误,而不是我想要的.我不知道如何解决这个问题.

我希望能够通过变量形式调用信息.

Sea*_*ght 7

paste testA.txt testB.txt testC.txt | sed -e 's/\t/ : /g'
Run Code Online (Sandbox Code Playgroud)

输出是:

something.awesome.com : 123 : 12.345.678.909
something2.awesome.com : 456 : 87.65.432.1
something3.awesome.com : 789 : 102.254.326.12

编辑:以下是使用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>&-
Run Code Online (Sandbox Code Playgroud)