awk 'FNR == NR { F[++n] = $1; next } FNR == 1 { T1 = $1 } { for (i = 1; i <= n; ++i) { x = ($1 - T1)/F[i]; print x - int(x) >"output" FNR} }' file2 file1
Сначала считывается содержимоеfile2
(первого файла, заданного в командной строке, который содержит единственный столбец )и сохраняется в массиве F
.
Затем он считывает file1
и для каждой строки вычисляет столько чисел, сколько значений содержится в массиве F
. Для каждой строки file1
эти вычисленные числа выводятся в файл с именем output
, за которым следует соответствующий номер строки в file1
.
Результаты:
$ ls
file1 file2 output1 output2 output3 output4
$ cat output1
0
0
0
0
$ cat output2
0
0.5
0.5
0.375
$ cat output3
0
0.5
0.5
0.125
$ cat output4
0
0.5
0.166667
0.125
$ cat output5
Скрипт awk
с аннотациями:
FNR == NR {
# This is the first file.
# Read its data into F, and then continue.
F[++n] = $1
next
}
# We are now only processing the second file.
FNR == 1 {
# Save T1 from the first line of the second file.
T1 = $1
}
{
# Loop through F and compute x for each.
for (i = 1; i <= n; ++i) {
x = ($1 - T1)/F[i]
# Print to the file given by the current line number.
print x - int(x) >"output" FNR
}
}
Я использую vim и tmux, и для работы с системным буфером обмена у меня есть следующее:
" copy and paste with clipboard
" paste from system CTRL-C clipboard
nnoremap <Leader>p "+p
" paste from system highlighted clipboard
nnoremap <Leader>P "*p
" copy contents of unnamed register to system CTRL-C clipboard
nnoremap <silent><Leader>y :call Preserve("normal! Gp\"+dGu")<cr>
\ :echo 'copied to CTRL-C clipboard'<cr>
" copy contents of unnamed register to system highlghted clipboard
nnoremap <silent><Leader>Y :call Preserve("normal! Gp\"*dGu")<cr>
\ :echo 'copied to highlight clipboard'<cr>
" run a command, but put the cursor back when it's done
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
Н.Б. Я не тратил много времени на тестирование следующего, но я обнаружил, что когда я подключаюсь по ssh к хосту (linux )и в сеансе tmux на хосте (, но не на клиенте ). ] что эти переназначения иногда могут копировать из безымянных регистров vim на хосте в системный буфер обмена на клиенте (и наоборот ). Мне нравится, когда он так себя ведет, но иногда они не разговаривают, не знаю почему..
В любом случае, я надеюсь, что это кому-то поможет!