Перекрестная ссылка Awk на 2 файла

Es posible que desee hacer algo como esto:

db_connect="user/pass@db"

output=$(
    sqlplus -s "$db_connect" <<'END' | sed '/^$/d'
        set heading off
        select value from v$parameter where name='spfile';
END
)

La opción -sy el comando set heading offsqlplus están destinados a minimizar los resultados extraños. sed '/^$/d'es para eliminar líneas vacías. El resultado en $outputdebe ser una cadena vacía (para un resultado nulo )o la línea (s )de la salida de la consulta.

Tenga en cuenta que el terminador ENDheredoc no debe tener ningún otro carácter en esa línea. Es por eso que no está sangrado como las otras líneas.

Entonces puedes hacer:

if [[ -n "$output" ]]; then
    stuff if there is output
else
    stuff if there is null output
fi
0
05.07.2019, 02:57
2 ответа

Описание проблемы могло бы быть яснее, но, судя по примеру, я думаю, вам нужно это:

awk -F: 'NR==FNR { d[$1]=1; next } !($1 in d) { print $0 }' 1.txt 2.txt

Аргумент -F:говорит: «рассматривать символ двоеточия ' :' как разделитель столбцов». (По умолчанию awkсчитает пробельные символы разделителем столбцов.)

Второй аргумент — это awkпрограмма, которая говорит

IF this line is from the first input file THEN
    In a dictionary named `d`, create an item whose key is the first column of the input line and whose value is 1
    Skip the rest of the program move on to process the next line

(because of the "skip to next line" above we only do this for lines from the second file)
IF the dictionary named `d` has no item whose whose key is the first column of this line THEN
    Print this line
2
28.01.2020, 02:22

Использование приведенной ниже команды работает отлично

awk 'NR==FNR {a[$0];next}($0 in a) {print $0}' 1.txt 2.txt
1
28.01.2020, 02:22

Теги

Похожие вопросы