I'm trying to make a On Screen Display with a count-down in the mouse-position every time I press a key.
So far, I was able to make multiple GUIs in the Mouse position every time I press the key and set up a Timer. But for some reason, I'm only capable of updating the last GUI created, even accessing it thru the Remarks.
Tabs := 0
Tab_OSD := 0
count := 0
return
F7::
CreateGUI("Gui" . Tabs)
SetTimer, Tick, 1000
Tabs++
;Tab_OSD := Tabs - 1
;Loop, %Tab_OSD%{
; GuiControl, Text, % "Gui" . A_Index . "", % "" . count . ""
; ;MsgBox, % "Iteration number is Gui" . A_Index . " and " . count
;}
return
CreateGUI(nome) {
MouseGetPos, StartX , StartY
StartX:=StartX-15
StartY:=StartY-15
Gui, % nome . ": New"
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, 000001
Gui, Font, s12
WinSet, TransColor, 000001
Gui, % nome . ":Add", Text, cReD , %nome%
Gui, % nome . ":Show", x%StartX% y%StartY% NoActivate
}
Tick:
count++
Gosub, UpdateOSD
return
UpdateOSD:
Tab_OSD := Tabs - 1
Loop, %Tab_OSD%{
GuiControl, Text, % "Gui" . A_Index . "", % "" . count . ""
;MsgBox, % "Iteration number is Gui" . A_Index . " and " . count
}
return
When I try to update the GUIs from the F7:: block (commented), it updates the last GUI. But when I try the same Loop on UpdateOSD, it don't update any Text.
If anyone can give me some light, I would be thankfull.
Found a way to make it work. It was missing a control variable in each GUI to update the text.
Another problem was that the name and control variable were being created on a function who didn't allow to use the variables out of that block.
Don't know if I could solve this another way, but creating the GUI on the trigger solved it.
I've also implemented a limit for the counter and Destroy the GUI when it's done.
Tabs := 1
count := 0
return
F7::
MouseGetPos, StartX , StartY
StartX:=StartX-40
StartY:=StartY-40
Gui, % "Gui" . Tabs . ": New",
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, 000001
Gui, Font, s16
WinSet, TransColor, 000001
Gui, % "Gui" . Tabs . ":Add", Text, % "vCtrl" . Tabs . " cReD", 00
Gui, % "Gui" . Tabs . ":Show", x%StartX% y%StartY% NoActivate
Tmp%Tabs% := 0
SetTimer, Tick, 1000
Tabs++
return
Tick:
count++
Gosub, UpdateOSD
return
UpdateOSD:
TabOSD := Tabs - 1
Loop, %TabOSD%{
Tmp%A_Index%++
if (Tmp%A_Index% > 45){
Gui, % "Gui" . A_Index . ": Destroy"
Tmp%A_Index% := 0
}
Tempo := Tmp%A_Index%
GuiControl, % "Gui" . A_Index . ":", % "Ctrl" . A_Index . "" , %Tempo%
}
count := 1
return
Related
Perl DBD::ODBC throwing error from sql server insert statement
DBD::ODBC does not yet support binding a named parameter more than once
when binding parameters in this script is not intended. I've tried answering this on my own, and continue to do so, but haven't had any luck with answers from similar questions asked.
I've got a script to load a csv (containing a combination of datetimes, guids, and comments/message strings) into a database. I've included part of my script below for further analysis if needed. It seems to be getting hung up on this error after 350,000+ lines(about 20 columns) into the csv, but I've been unable to figure out exactly what is causing it.
I've tried setting
$self->{dbh}->{odbc_ignore_named_placeholders} = 1;
but with no success in getting past that error. All values in the csv are enclosed in single-quotes, but some of those values are strings containing either/both : and ?.
I'm not looking to use binding parameters, or named placeholders, in this scenario -- only to get the raw data into a database.
There's quite a bit of printing in this part of the script as a result of trouble-shooting. the script overall hasn't been intentionally/unintentionally optimized yet -- the goal for me is to just get it working. be kind.
This instantiates the "Connection" object. since the connection is made here, and assigned to $self->{dbh}, I should be able to assign 1 to {odbc_ignore_named_placeholders}, but it doesn't seem to be working.
sub New {
my $class = shift;
my $self = {
dbh => DBI->connect( $dsn ),
dropIfExists => 1, # 1 == drop, 0 == do not drop or create
debug => 1, # 1 == enabled, 0 == disabled
};
$self->{dbh}->{odbc_ignore_named_placeholders} = 1;
bless $self, $class;
return $self;
}
Here's the important bit that prepares the lines in an insert statement:
while ( my $row = $csv->getline( $fh ) ) {
my #fields = #{$row};
my #newline = ();
for ( #fields ) {
my $str = $_;
$str =~ s/'+/''/;
my $newString = "'" . $str . "'";
print $newString.NewLine;
push( #newline, $newString );
}
my $line = join( ",", #newline );
$values .= "(" . $line . "),";
$MasterLineCount++;
print FancyLine;
print "MasterLineCount: " . $MasterLineCount . NewLine;
print FancyLine;
$count++;
print FancyLine;
print "Line count: ".$count.NewLine;
print FancyLine;
# sql server allows a maximum of 1000 values (rows) in a
# single insert statement, so this stops the loop, and
# prepares/executes the query. if the loop hits the end of
# the file with a count < 999, it drops out of the
# while loop, and checks if count > 0, if it is, it
# prepares/executes the statement for the remaining
# rows/lines
if ( $count == 999 ) {
$statementCount++;
print FancyLine;
print "Statement Count: " . $statementCount . NewLine;
print FancyLine;
my $insertStmt = "insert into " . $db_name . ".dbo." . $tableName . " (" . $colNames . ") values " . $values;
my $chopTrailingComma = chop( $insertStmt );
# print "Insert Statement: ".NewLine;
# print FancyLine;
# print $insertStmt.NewLine;
# print FancyLine;
# load table
$self->ExecuteStmt( $insertStmt );
#reset values string
$values = "";
#reset count
$count = 0;
}
}
if ( $count > 0 ) {
$statementCount++;
print FancyLine;
print "Statement Count: " . $statementCount . NewLine;
print FancyLine;
my $insertStmt = "insert into " . $db_name . ".dbo." . $tableName . " (" . $colNames . ") values " . $values;
my $chopTrailingComma = chop( $insertStmt );
# load table
$self->ExecuteStmt( $insertStmt );
#reset values string
$values = "";
#reset count
$count = 0;
}
For clarity, this is ExecuteStmt():
sub ExecuteStmt {
my $self = shift;
my $stmt = shift;
$self->{sth} = $self->{dbh}->prepare( $stmt );
$self->{sth}->execute or die "$stmt".NewLine().FancyLine().$self->{sth}->errstr;
}
alright, i figured out a way around it and its unrelated to the dbi module. when creating a new Text::CSV object, pass in the following parameter:
verbatim => 1,
this is what my Text::CSV constructor looks like now:
my $csv = Text::CSV_XS->new( { binary => 1,
eol => $/,
always_quote => 1,
verbatim => 1,
skip_empty_rows => 1
} );
from the documentation Text::CSV:
> This is a quite controversial attribute to set, but makes some hard
> things possible.
>
> The rationale behind this attribute is to tell the parser that the
> normally special characters newline (NL) and Carriage Return (CR) will
> not be special when this flag is set, and be dealt with as being
> ordinary binary characters. This will ease working with data with
> embedded newlines.
>
> When verbatim is used with "getline", "getline" auto-chomp's every line.
I will update this question/answer if i discover any unintended consequences relating to this change.
i use parrot security as my daily distro. its mate terminal is transparent so is vim .but i wanted to get auto complete and used some plugins.auto complete window appears to be in pink which looks really ugly in semi transparent black background.i changed the theme and it was fixed but so was gone vim transparency .
in short word (1)i have to keep the default (2)i have to keep
transparent vim (3)i have to change the auto complete window from
pink to semi transparent black
here is my init.vimrc
set number
set expandtab
set autoindent
set softtabstop=4
set shiftwidth=4
set tabstop=4
"Enable mouse click for nvim
set mouse=a
"Fix cursor replacement after closing nvim
set guicursor=n-v-c-sm:block,
"Shift + Tab does inverse tab
inoremap <S-Tab> <C-d>
"See invisible characters
set list listchars=tab:>\ ,trail:+,eol:$
let $NVIM_TUI_ENABLE_CURSORE_SHAPE=1
"wrap to next line when end of line is reached
set whichwrap+=<,>,[,]
"-----------------------------------------------------------
"===========================================================
"-----------------------------------------------------------
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/nerdtree'
Plug 'tsony-tsonev/nerdtree-git-plugin'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
Plug 'airblade/vim-gitgutter'
Plug 'ctrlpvim/ctrlp.vim' " fuzzy find files
Plug 'scrooloose/nerdcommenter'
Plug 'christoomey/vim-tmux-navigator'
Plug 'morhetz/gruvbox'
Plug 'HerringtonDarkholme/yats.vim' " TS Syntax
Plug 'joshdick/onedark.vim'
Plug 'sheerun/vim-polyglot'
Plug 'sheerun/vim-polyglot'
" File Explorer
Plug 'scrooloose/NERDTree'
" Auto pairs for '(' '[' '{'
Plug 'jiangmiao/auto-pairs'
Plug 'http://github.com/tpope/vim-surround' " Surrounding ysw)
Plug 'https://github.com/preservim/nerdtree' " NerdTree
Plug 'https://github.com/tpope/vim-commentary' " For Commenting gcc & gc
Plug 'https://github.com/vim-airline/vim-airline' " Status bar
Plug 'https://github.com/lifepillar/pgsql.vim' " PSQL Pluging needs :SQLSetType pgsql.vim
Plug 'https://github.com/ap/vim-css-color' " CSS Color Preview
Plug 'https://github.com/rafi/awesome-vim-colorschemes' " Retro Scheme
Plug 'https://github.com/neoclide/coc.nvim' " Auto Completion
Plug 'https://github.com/ryanoasis/vim-devicons' " Developer Icons
Plug 'https://github.com/tc50cal/vim-terminal' " Vim Terminal
Plug 'https://github.com/preservim/tagbar' " Tagbar for code navigation
Plug 'https://github.com/terryma/vim-multiple-cursors' " CTRL + N for multiple cursors
call plug#end()
inoremap jk <ESC>
nmap <C-n> :NERDTreeToggle<CR>
vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle
" open NERDTree automatically
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * NERDTree
let g:NERDTreeGitStatusWithFlags = 1
"let g:WebDevIconsUnicodeDecorateFolderNodes = 1
"let g:NERDTreeGitStatusNodeColorization = 1
"let g:NERDTreeColorMapCustom = {
"\ "Staged" : "#0ee375",
"\ "Modified" : "#d9bf91",
"\ "Renamed" : "#51C9FC",
"\ "Untracked" : "#FCE77C",
"\ "Unmerged" : "#FC51E6",
"\ "Dirty" : "#FFBD61",
"\ "Clean" : "#87939A",
"\ "Ignored" : "#808080"
"\ }
let g:NERDTreeIgnore = ['^node_modules$']
" vim-prettier
"let g:prettier#quickfix_enabled = 0
"let g:prettier#quickfix_auto_focus = 0
" prettier command for coc
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" run prettier on save
"let g:prettier#autoformat = 0
"autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
" ctrlp
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
" j/k will move virtual lines (lines that wrap)
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
set relativenumber
set smarttab
set cindent
set tabstop=4
set shiftwidth=4
" always uses spaces instead of tab characters
set expandtab
" sync open file with NERDTree
" " Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()
" coc config
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-pairs',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-prettier',
\ 'coc-json',
\ ]
" from readme
" if hidden is not set, TextEdit might fail.
set hidden " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " Better display for messages set cmdheight=2 " You will have bad experience for diagnostic messages when it's default 4000.
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Or use `complete_info` if your vim support it, like:
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <F2> <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <C-d> <Plug>(coc-range-select)
xmap <silent> <C-d> <Plug>(coc-range-select)
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" use `:OR` for organize import of current buffer
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Using CocList
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
if (has("termguicolors"))
set termguicolors
endif
"onedark theme"
syntax on
so what should i so?
If you are using neovim there is an option called :h pumblend which can be used to change the transparency of the popup menu.
Are you sure gruvbox caused your vim to lose transparency? I am not sure if vim is able to change a terminal emulator's transparency. I or someone else might be able to advise you better if you post pictures of what has changed.
I have a file with this structure:
http://paste.ubuntu.com/21136265/
And I have to capture all the data from the line 'ADSTART ACTION(ADD)' to the next line with this same text, to create a single record, or line.
Sorry but I Can't post an example of the output because is all the data between the 'ADSTART' lines in a single line or record, I'm working under z/OS and we have the concept of record length.
I'm trying this in REXX for z/OS and in AWK in UNIX SYSTEM SERVICES for z/OS, but I'm stuck putting all fields in a line, and I can't figure out how to do it.
I'm capturing the data trough nested loops, but I don't know haw to put it in a single line.
If you're using REXX then why don't you just use the parse instruction to scrape the report file? The parse instruction uses a template pattern which is very simple but powerful.
Here's an example:
/* REXX */
queue "ADSTART ACTION(ADD)"
queue " ADID(ABCD0B ) ADVALFROM(111230) CALENDAR(CALSEM7J )"
queue " DESCR('DESCRIPTION ')"
queue " ADTYPE(A)"
queue " GROUP(PBQOPC )"
queue " OWNER('OWNER1')"
queue " PRIORITY( 5) ADSTAT(A)"
queue " ODESCR('ALADIN ')"
queue "ADRUN ACTION(ADD)"
queue " PERIOD(HEB ) RULE(3) VALFROM(091230) VALTO(711231)"
queue " SHIFT( 0) SHSIGN(F)"
queue " DESCR('DESCRIPTION')"
queue " TYPE(N)"
queue " IADAYS( 1, 2, 3, 4, 5, 6, 7)"
queue " IATIME(1700) DLDAY( 1) DLTIME(0600)"
do while queued() > 0
parse pull rec
select
when startswith(rec,"ADSTART") then do
p. = '' /* the output record */
parse var rec with . 'ACTION('p.action')'
do queued()
parse pull rec
if left(rec,1) /= ' ' then do
/* End of parameter group. Re-queue the record and break */
push rec
leave
end
select
when startswith(rec, " ADID") then do
parse var rec with . "ADID("p.adid") ADVALFROM("p.advalfrom")" ,
"CALENDAR("p.calendar")"
end
when startswith(rec, " DESCR") then do
parse var rec with "DESCR('"p.desc"')"
end
when startswith(rec, " PRI") then do
parse var rec with "PRIORITY("p.priority") ASTAT("p.adstat")"
end
otherwise nop
end
end
/* write out the record in 1 line */
say strip(p.action) strip(p.adid) strip(p.advalfrom) strip(p.calendar),
strip(p.desc) strip(p.priority) strip(p.adstat)
end
when startswith(rec,"ADRUN") then do
/* do some stuff to parse this */
end
otherwise nop
end
end
exit 0
startswith:
parse arg input, prefix
input_len = length(input)
if input_len = 0 then return 0
prefix_len = length(prefix)
if prefix_len = 0 then return 0
return input_len >= prefix_len & left(input,prefix_len) = prefix
Seeing as you're comfortable in z/OS UNIX environment, if you want something a little bit more powerful than REXX and/or AWK you should checkout my z/OS port of Lua. It comes with an LPeg package which makes it trivially easy to write lexers and parsers with very few lines of code.
If all you want to do is text flow the TWS control statements onto one line without capturing the fields then that's very simple to do.
/* REXX */
queue "ADSTART ACTION(ADD)"
queue " ADID(ABCD0B ) ADVALFROM(111230) CALENDAR(CALSEM7J )"
queue " DESCR('DESCRIPTION ')"
queue " ADTYPE(A)"
queue " GROUP(PBQOPC )"
queue " OWNER('OWNER1')"
queue " PRIORITY( 5) ADSTAT(A)"
queue " ODESCR('ALADIN ')"
queue "ADRUN ACTION(ADD)"
queue " PERIOD(HEB ) RULE(3) VALFROM(091230) VALTO(711231)"
queue " SHIFT( 0) SHSIGN(F)"
queue " DESCR('DESCRIPTION')"
queue " TYPE(N)"
queue " IADAYS( 1, 2, 3, 4, 5, 6, 7)"
queue " IATIME(1700) DLDAY( 1) DLTIME(0600)"
do while queued() > 0
parse pull rec
if left(rec,1) /= ' ' then do
line = rec
do queued()
parse pull rec
if left(rec,1) /= ' ' then do
push rec;leave
end
line = line rec
end
say space(line,1)
end
end
exit 0
Try this;
sed -n '/ADSTART ACTION(ADD)/,/ADRUN/p' <filename> | sed 's/ADRUN ACTION(ADD)//g'
Maybe this would do it:
awk '/ADSTART ACTION\(ADD\)/{print buf; buf=""} {buf=buf""$0" "} END{print buf}' test.in
Commented version:
/ADSTART ACTION\(ADD\)/ { # for records where ADSTART occurs
print buf # output the buffer variable
buf="" # then empty the buffer
}
{ # for all records
# gsub(/^ +| +$/,"") # here you could trim leading and trailing space
buf=buf""$0" " # build the buffer
}
END { # in the end
print buf # output the remaining buffer
}
Although the solution above could work for not many lines per block, a solution that only prints the text between ADSTART ACTION (ADD) and assumes only one block will be printed
Bash:
gawk 'BEGIN{s=0} /ADSTART.*ACTION(ADD)/ {s=(s+1)%2} (s==1){ print }' | sed ':a;N;$!ba;s/\n//g'
(ADSTART... lines are omitted)
Thank you very much for all the answers.
At last it was pretty easy, because when I do an FTP from z/OS to USS (Unix System Services for z/OS) in binary, all the data is in one line.
At first I was working with a file transfered with FTP (ASCII xlate) to my PC, and then transmitted to USS in binary FTP with WinSCP.
This is the code I used to replace a text pattern with carriage return:
sed 's/ADSTART ACTION(ADD)/\
/g' <input file> ><output file>
with carriage return inserted by pressing enter key, because /r /'$''' /n /x0D didn't worked in USS, I don't know why.
Thank you all again for your time.
Patricio.
I am new to Perl and need some guidance. I have multiple text files and want to merge all them into a new csv file. Then, from the csv file, I want to split the string into multiple column as shown in the "Output" format below. Can someone pls help me?
Text File#1.txt
Name:A
Test1:80
Test2:60
Test3:50
Text File#2.txt
Name:B
Test1:85
Test2:78
Test3:60
Output (format #1):
New Text File#3.csv
Name Test1 Test2 Test3
A 80 60 50
B 85 78 60
Output (format #2):
New Text File#3.csv
Name Test Data
A 1 80
A 2 60
A 3 50
B 1 85
B 2 78
reading files:
Open FILE, "filename.txt" or die $!;
#create hash
%hash = ();
#read file - you have to do this for all files
while (<FILE>) {
if(first_row){
$name = (split ':')[1];
}else{
$points = split ':'[1];
push( #{$hash{$name}}, $points );
}
}
at this point you have a hash:
A -> [80,60,50]
B -> [85,78,60]
you can now use this hash to print your csv file:
for file 1:
open CSV1, ">", "1.csv" or die $!
foreach my $name( keys %hash )
{
$points = $hash{$name};
print CSV1 $name + ";" + join(";", #{$points})
print "/n";
}
for file 2:
open CSV2, ">", "2.csv" or die $!
foreach my $name( keys %hash )
{
$points = $hash{$name};
$testnumber = 0;
foreach $point ( in #$points){
print CSV2 $name + ";" $testnumber+1 + ";" + $point + "\n";
}
}
hope this helps you out, if anything is not clear, you can ask.
do not copy paste, it can contain minor errors, but i assume the way of thinking is clear
Update: the ";" is because csv split columns on that character
please feedback
I have this in the .sql file in my buffer:
CREATE TABLE WH.dbo.customer(
id INTEGER NOT NULL,
cust_name VARCHAR(30) NOT NULL,
phone_nbr VARCHAR(30) NULL,
PRIMARY KEY(id)
);
If I am in normal mode and the cursor is on TABLE then I sould be able to hit either <Leader>se or command gVim to :DBExecSQLUnderCursor and the statement should be executed as dbext should find CREATE and ; and then execute the script in between. But i get the following message:
Last SQL:
CREATE TABLE WHAnalysis.dbo.customer(
If I highlight all the script and choose Execute SQL (Visual selection) from the plugin menu then it runs fine.
What is going on? Could it be a setting in my _vimrc?:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
" Use CTRL-S for saving, also in Insert mode
:nnoremap <C-S> :<C-U>update<CR>
:vnoremap <C-S> :<C-U>update<CR>gv
:cnoremap <C-S> <C-C>:update<CR>
:inoremap <C-S> <C-O>:update<CR>
" Microsoft SQL Server
let g:dbext_default_profile_WH = 'type=SQLSRV:user=dbuser:passwd=dbuserpassword:dsnname=SQLOLEDB.1:srvname=dwdb'
set nocp
call pathogen#infect()
syntax on
filetype plugin indent on
"Mouse and backspace
set mouse=a
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
nnoremap <Leader>p :pyf P:\Computer Applications\Python\
"quick quit command
noremap <Leader>e :quit<CR> "quits the current window
" Rebind <Leader> key
let mapleader = ","
map <Leader>n <esc>:tabprevious<CR>
map <Leader>m <esc>:tabnext<CR
I spoke to the plugin maintainer David Fishburn - I was amazed at the time-out he took to help a novice like me: great guy.
Initially he suggested
I believe the cmd terminator for SQLSRV is "\ngo\n" not ";".
If you want to change it temporarily to try in this buffer run:
:DBSetOption cmd_terminator=';'
Try the cmd again.
If that works you can either override the default or change your
profile to override it.
Then in answer to some further related questions:
Q1. What is "\ngo\n" ?
Because the string is enclosed in double quotes, Vim treats escaped
characters differently. \n - newline go \n - newline
So for SQL Server this would be typical:
CREATE PROCEDURE
BEGIN
END
go
Which is actually:
"END\ngo\n"
In other words, "go" has to be on a newline, with only "go" on the
line.
Q2. Do I just add the following to _vimrc for it to become permanent?:
DBSetOption cmd_terminator=';'
No. :DBSetOption is used to modify current buffer settings only, not
permanent settings.
The best thing you can do is read through :h dbext.txt.
The specific answer to your question lies in :h dbext-configure-options
5.3 Database Specific Options dbext-configure-options
The command terminator is automatically added to a command before it is
sent to the database. The command options are also added to the command
line used to execute the statement. >
dbext_default_SQLSRV_bin = "osql"
dbext_default_SQLSRV_cmd_header = ""
dbext_default_SQLSRV_cmd_terminator = "\ngo\n"
dbext_default_SQLSRV_cmd_options = '-w 10000 -r -b -n'
dbext_default_SQLSRV_extra = ''
So, to permanently override for all buffers in your .vimrc you would
add:
let g:dbext_default_SQLSRV_cmd_terminator = ";"