Почему zsh ведет себя как меньший при запросе к базе данных (postgresql)?

Надеюсь, это не домашнее задание? ;-) Сложность в том, что вы не хотите пересчитывать букву «L» в Меллере дважды, верно? Отсюда и «отличное».

$cat t
my nice name is Mike Meller

И затем конвейер команд для преобразования:

$tr '[a-z]' '[A-Z]' < t |     # Convert all to upper case
fold -b -w 1 |                # Break into one letter per line
awk -f t.awk |                # Pipe the whole mess to awk to count
sort -r -n                    # Sort in reverse numeric order

Сценарий awk лучше всего разбить в отдельный файл, хотя вы можете просто поместить его все в однострочник bash:

$cat t.awk    
/ / {                         # Match spaces,
  for (c in wc) {dc[c]+=1}    #  Accumulate word count (wc) into doc count (dc)
  split("",wc)                #  Reset the word count
}

!/ / {                        # Match non-spaces,
  if (wc[$1] == "") wc[$1]=1  #  If haven't already seen char in this word, mark it Donny
}

# Finally, output the count and the letter
END {
  for (c in wc) {dc[c]+=1}    # Accumulate one last time, in case there is no trailing space
  for (c in dc) {print c, dc[c]}
}

Что производит (для меня ) этот вывод:

$tr '[a-z]' '[A-Z]' < t | fold -b -w 1 | awk -f t.awk  | sort -r -n
4 M
4 E
3 I
2 N
1 Y
1 S
1 R
1 L
1 K
1 C
1 A
2
04.11.2016, 21:45
2 ответа

Возможно, ваша оболочка устанавливает переменную среды PAGER .

Попробуйте отключить его перед запуском psql:

user@host% unset PAGER

Вы также можете попытаться установить значение pset для пейджера на "off", как это показано в оболочке postgresql:

user=> \pset pager off

Это включит или выключит использование пейджера. Вы также можете настроить его на использование определенного пейджера (например, more , less , cat и т. Д.).

Дополнительная информация на странице руководства psql:

pager

    Controls use of a pager for query and psql help output. If the
environment variable PAGER is set, the output is piped to the
specified program. Otherwise a platform-dependent default (such as
more) is used.

    When the pager is off, the pager is not used. When the pager is on,
the pager is used only when appropriate, i.e. the output is to a
terminal and will not fit on the screen. (psql does not do a perfect
job of estimating when to use the pager.) \pset pager turns the pager
on and off. Pager can also be set to always, which causes the pager to
be always used.
2
27.01.2020, 22:10

Вы можете вообще отключить его, написав комментарий

cat ~/.oh-my-zsh/lib/misc.zsh
...
#env_default 'PAGER' 'less'                                                        
#env_default 'LESS' '-R'                                                           
...

Затем откройте новый терминал и повторите попытку.

2
14.04.2021, 16:43

Теги

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