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 -s
y el comando set heading off
sqlplus están destinados a minimizar los resultados extraños. sed '/^$/d'
es para eliminar líneas vacías. El resultado en $output
debe 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 END
heredoc 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
Описание проблемы могло бы быть яснее, но, судя по примеру, я думаю, вам нужно это:
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
Использование приведенной ниже команды работает отлично
awk 'NR==FNR {a[$0];next}($0 in a) {print $0}' 1.txt 2.txt