Как совместить текстовое сообщение с системным сообщением?

Предполагая, что все имена ваших файлов начинаются с table (если это не так, просто измените шаблон glob на что-то, что соответствует им всем), вы можете сделать следующее:

for file in table*; do
    awk -vi="2099 12    31" '1;END{if($0!=i){print i,$NF}}' "$file" > "$file".new
done

Команда awk определяет переменную i как недостающую строку. Блок 1; просто печатает каждую строку, а блок END{} выполняется, когда весь файл прочитан. Когда внутри блока END{}, $0 будет последней прочитанной строкой, последней строкой файла. Если она не равна значению i, выведите i и последнее поле (NF) последней строки файла.

6
14.02.2018, 18:46
6 ответов

Una forma sencilla sería:

printf "The system time is %s.\n" "$(date)"

También puede usar la interpolación de cadenas:

echo "The system time is $(date)."
14
27.01.2020, 20:20

Con fecha GNU:

date +"The system time is %a %b %d %T %Z %Y"
12
27.01.2020, 20:20

Directamente:

date +"The system time is %c"
  • %c-fecha y hora del lugar
8
27.01.2020, 20:20

En los viejos tiempos, lo hicimos

echo The system time is `date`.

Pero los acentos graves para la sustitución de comandos están en desuso en estos días. Use esto en su lugar

echo The system time is $(date).

(solo 1 carácter adicional para escribir ).No necesitas comillas dobles apestosas.

0
27.01.2020, 20:20

Con Bash 4.2 y superior, puede usar printf:

printf "The system time is %(%a %b %d %T %Z %Y)T\n"
1
27.01.2020, 20:20

Trivialmente:

echo -n 'The system time is '; date

Requiere echoque respeta el interruptor -n, pero tendría que buscar profundamente para encontrar un sistema donde no (o usarprintf).

0
27.01.2020, 20:20

Теги

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