H2-folks,
I have a H2-Database-Table like this:
CREATE TABLE Achimv
(
NAME CHAR(10)
, VORNAME CHAR(10)
, PLZ CHAR(10)
)
;
and I have got a CSV-File with '$' as row separators:
Berger $Willi$26531
Meyer $Hans $85322
Klausen$Till $52389
and the INSERT-Statements work perfectly as follows:
INSERT INTO Achimv
SELECT * FROM CSVREAD
('E:/Achimv.csv',
' NAME
$ VORNAME
$ PLZ
', 'charset=UTF-8 fieldSeparator=$');
But now the table should be filled with the first two rows being
AES-encrypted and the third one not.
My modification (done like in the H2-Dokumentation-pdf):
. . . . .
('E:/Achimv.csv',
' ENCRYPT('AES', '00', STRINGTOUTF8(NAME))
$ ENCRYPT('AES', '00', STRINGTOUTF8(VORNAME))
$ PLZ
', 'charset=UTF-8 fieldSeparator=$');
ended with a SQL-Syntax-Error:
. . .
' ENCRYPT('AES[*]', '00', STRINGTOUTF8(NAME))
How is it possible to load CSV-data with CSVREAD in combination with ENCRYT ?
Thanks in advance
Achim
INSERT INTO Achimv
SELECT
ENCRYPT('AES', '00', STRINGTOUTF8(NAME)),
ENCRYPT('AES', '00', STRINGTOUTF8(VORNAME)),
PLZ
FROM CSVREAD
('E:/Achimv.csv',
' NAME
$ VORNAME
$ PLZ
', 'charset=UTF-8 fieldSeparator=$');
Related
I have a data frame and I want to extract the specific string on one of the columns by delimiter but there are several conditions. I want to mutate a new column that contain the COSVxxxx strings only.
df:
ID
.
COSV50419740
.
.
.
rs375210814
.
rs114284775;COSV60321424
.
.
.
rs67376798;88974
rs1169783812
rs56386506;51676;COSV66451617
rs80358907;52202
.
.
.
482972
629301
COSV66463357
rs80358408;51066
rs80358420;51100;COSV66464432
desired df:
ID COSV.ID
. .
COSV50419740 COSV50419740
. .
. .
. .
rs375210814 rs375210814
. .
rs114284775;COSV60321424 COSV60321424
.
.
.
rs67376798;88974 rs67376798;88974
rs1169783812 rs1169783812
rs56386506;51676;COSV66451617 COSV66451617
rs80358907;52202 rs80358907;52202
. .
. .
. .
482972 482972
629301 629301
COSV66463357 COSV66463357
rs80358408;51066 rs80358408;51066
rs80358420;51100;COSV66464432 COSV66464432
I want to keep the string if there are no COSV annotation. However, my problem is that there are some rows containing from one to four annotation by colon delimiter. I tried to use cSplit function to separate them but have no idea how to convert the COSV string into one column.
You could use sub here, e.g.
df$ID_new <- ifelse(grepl("\\bCOSV\\d+\\b", df$ID),
sub("^.*\\b(COSV\\d+)\\b.*$", "\\1", df$ID),
NA)
This option will assign the (last) COSV value, should it exist in the ID column, otherwise it will assign NA.
Need to remove the last seven characters from a variable.
For example if my variable string is
COLUMN_NAME||','||
then it should output COLUMN_NAME
I have tried the below but last pipe symbol only getting removed
var=$(lastline%|)
var=$(lastline%|*)
Result : COLUMN_NAME||','|
To remove the last 7 characters:
$ var="COLUMN_NAME||','||"
$ echo "${var%???????}"
COLUMN_NAME
To remove everything after the first pipe:
$ echo "${var%%|*}"
COLUMN_NAME
See https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion
and https://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching
The old school way
echo "COLUMN_NAME||','||" | rev|cut -c 8-|rev
So you are just reversing the string, deleting first 7 characters and again reversing the string.
Use the $variable with echo to do the same.
You can also use awk like below which would be faster.
awk '{print substr($0, 1, length($0)-7)}'
Example:
$ export variable1="COLUMN_NAME||','||"
$ echo $variable1|rev|cut -c 8-|rev
COLUMN_NAME
$ echo $variable1|awk '{print substr($0, 1, length($0)-7)}'
COLUMN_NAME
You need to use two % to strip the longest match:
$ r="COLUMN_NAME||','||"
$ echo ${r%%|*}
COLUMN_NAME
As BashFAQ says in Removing part of a string:
% means "remove the shortest possible match from the end of the
variable's contents".
%% means "remove the longest possible match from the end of the
variable's contents".
You could find the length of your string/s and index from that point:
str1="1234567890foobar";
strlen=${#str1};
str2=${str1:0:$strlen-7};
echo $str2;
I think I've tried every intuitive combination of these four commands, with and without colons, in my _vimrc:
syntax enable
syntax on
set filetype=r
set syntax=r
But when I open a script in gVim, it's all one solid color. Within a session, both ':set syntax=r' and ':set filetype=r' work fine, while the other two do nothing.
My full _vimrc is below:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set keymodel-=stopsel
set diffexpr=MyDiff()
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
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
"show line numbers
set number
"syntax highlighting for R
"syntax enable
syntax on
set filetype=r
"set syntax=r
colorscheme elflord
"see commands as they're being typed
set showcmd
"change the key combo for normal mode to 'jk'
inoremap jk <ESC>
"add line below cursor in insert mode
:autocmd InsertEnter * set cul
:autocmd InsertLeave * set nocul
This problem to me is harder than it might sound. I imported a GML file. I now have all of my rows with numbers followed by a ,. I can't figure out how to remove and make numeric. I have tried as.numeric and gsub, but when I do my adjacency matrix I get this output:
[1,] . 1 . . 1 . . . . 1 . . . . . . 1 . . . . . . 1 . . . . . . . . . 1 . 1 . . . ......
[2,] 1 . . . . . . . . . . . . . . . . . . . . . . . . 1 . 1 . . . . . 1 . . . 1 . ......
I need the numbers in the [1,] to be a real number so I can attempt a loop that I will come back later for help on!
This code doesn't work:
games[0] <- as.numeric(gsub("[^[:digit:]]","",games[0]))
I get this error:
Error in `[<-.igraph`(`*tmp*`, 0, value = numeric(0)) :
Logical or numeric value must be of length 1
Here is the code I have:
library(igraph)
games <- read.graph("football.gml", format="gml")
and I eventually need to be able to look this algorithm:
get.shortest.paths(games, 1, 155, weights = NULL ,output=c("vpath", "epath", "both"))
[1,] is a row with multiple values (one for each column), not a single string. gsub returns an error because it is only designed for use on a single string. You need to loop over each value in the n x k matrix (or use an apply function to do this) and apply the gsub function to each individual value. Also not sure why you are replacing "[^[:digit:]]". Keep in mind this will substitute out the literal string "[^[:digit:]]" , not whatever this references in R. Here is an example in a loop:
for (i in 1:nrow(data)){
for (j in 1:ncol(data)){
data[i,j] <- gsub(".", "", data[i,j])
}
}
Maybe you could do something creative like this:
read.table(text='1 2 3 4 ,
5 6 7 8 ,
9 1 2 3 ,', sep=' ', na.strings=',')
And then drop the last column.
I have to extract value of a variable which occurs multiple times in a file. for example, I have a text file abc.txt . There is a variable result. Suppose value of result in first line is 2, in third line it is 55 and in last line it is 66.
Then my desired output should be :
result:2,55,66
I am new in unix so I could not figure out how to do this. Please help
The contents of text file can be as follows:
R$#$#%$W%^BHGF, result=2,
fsdfsdsgf
VSDF$TR$R,result=55
fsdf4r54
result=66
Try this :
using awk code :
awk -F'(,| |^)result=' '
/result=/{
gsub(",", "", $2)
v = $2
str = (str) ? str","v : v
}
END{print "result:"str}
' abc.txt
Using perl code :
perl -lane '
push #arr, $& if /\bresult=\K\d+/;
END{print "result:" . join ",", #arr}
' abc.txt
Output :
result:2,55,66