I want to add a key directory directly under HKEY_CLASSES_ROOT with batch command (as like a subfolder) - regedit

I want to add a key folder (..NewKey) directly under HKEY_CLASSES_ROOT with batch command (as like a subfolder, on the left side), and then add several keys into this key folder. If i try to do it manualy, and right click HKEY_CLASSES_ROOT i can do this with add key (see picture1) If i try it with reg add command like below, the key is generated directly in HKEY_CLASSES_ROOT (see picture2) What am i doing wrong?
reg add "HKEY_CLASSES_ROOT" /v ..NewKey /t REG_SZ /d Server

You need to specify the new key name as part of the KeyName parameter, then speecify /ve. This creates the key with an empty (Default) value. Optionally, add the /t and /d parameters with approproate values to create the key with a non-empty (Default) value.
reg add "hkcr\...NewKey" /ve
or
reg add "hkcr\...NewKey" /ve /t REG_SZ /d "Server"
REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d
Data] [/f]
[/reg:32 | /reg:64]
KeyName [\Machine]FullKey
Machine Name of remote machine - omitting defaults to the
current machine. Only HKLM and HKU are available on remote
machines.
FullKey ROOTKEY\SubKey
ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ]
SubKey The full name of a registry key under the selected ROOTKEY.
/v The value name, under the selected Key, to add.
/ve adds an empty value name (Default) for the key.
/t RegKey data types
[ REG_SZ | REG_MULTI_SZ | REG_EXPAND_SZ |
REG_DWORD | REG_QWORD | REG_BINARY | REG_NONE ]
If omitted, REG_SZ is assumed.
/s Specify one character that you use as the separator in your
data
string for REG_MULTI_SZ. If omitted, use "\0" as the separator.
/d The data to assign to the registry ValueName being added.
/f Force overwriting the existing registry entry without
prompt.

Related

How to insert content of a file in different fields in mysql database using shell script?

I am trying to scan a folder for new files and reading those files and inserting its content into database and then delete file from folder.Till here its working but the issue that the whole content is getting inserted in one field in database.
Below is the code:
inotifywait -m /home/a/b/c -e create -e moved_to |
while read path action file; do
for filename in `ls -1 /home/a/b/c/*.txt`
do
while read line
do
echo $filename $line
mysql -uroot -p -Bse "use datatable; INSERT INTO
table_entries (file,data ) VALUES ('$filename','$line'); "
done <$filename
done
find /home/a/b/c -type f -name "*.txt" -delete
done
Basically the files contains:name,address,contact_no,email.
I want to insert name from file to name field in database,address in address. In php we use explode to split data,what do i use in shell script ?
This would be far easier if you use LOAD DATA INFILE (see the manual for full explanation of syntax and options).
Something like this (though I have not tested it):
inotifywait -m /home/a/b/c -e create -e moved_to |
while read path action file; do
for filename in `ls -1 /home/a/b/c/*.txt`
do
mysql datatable -e "LOAD DATA LOCAL INFILE '$filename'
INTO TABLE table_entries (name, address, contact_no, email)
SET file='$filename'"
done
find /home/a/b/c -type f -name "*.txt" -delete
done
edit: I specified mysql datatable which is like using USE datatable; to set the default database. This should resolve the error about "no database selected."
The columns you list as (name, address, contact_no, email) name the columns in the table, and they must match the columns in the input file.
If you have another column in your table that you want to set, but not from data in the input file, you use the extra clause SET file='$filename'.
You should also use some error checking to make sure the import was successful before you delete your *.txt files.
Note that LOAD DATA INFILE assumes lines end in newline (\n), and fields are separated by tab (\t). If your text file uses commas or some other separator, you can add syntax to the LOAD DATA INFILE statement to customize how it reads your file. The documentation shows how to do this, with many examples: https://dev.mysql.com/doc/refman/5.7/en/load-data.html I recommend you spend some time and read it. It's really not very long.

Automatically rename csv file via batch-file

I try to "automatically" rename a part of the name of my csv files (named
(e.g.) ´Trendreporting - 10.csv´ to ´Trendreporting.csv´) in a specific folder via batch file.
To make it clearer, I want to change this:
Trendreporting - 10.csv ( the part behind the - is variable: (so e.g. also Trendreporting - 07.csv) but there´s always only 1 csv file in the folder at a time)
To this:
Trendreporting.csv
I tried it already with this query:
#echo off
setlocal enableDelayedExpansion
for %%A in (TrendReporting - *.csv) do (
set "name=%%A"
ren TrendReporting - *.csv **
)
But nothing is happening when I execute the file - where´s the mistake?
#echo off
setlocal
ren "TrendReporting - *.csv" "Trendreporting.csv"
The name containing the spaces must be enclosed in quotes, otherwise optional.
You don't need delayedexpansion, nor a for, nor do you need to pointlessly set name

Passing spool file name to SQL script as a parameter from batch file - unexpected behaviour

When I pass in a name for a spool file, I get an incorrect file name. For example, I double-click command.bat and enter 'TEST' (without quotes) at the prompt and hit enter. Script runs and queries that database properly, but my output file is 'TESTcsv.LST' (again without quotes). If I change the file name to a proper 'TEST.csv', I can see that the output is correct.
command.bat:
#echo off
SET /P name="Enter name: "
sqlplus username/password #script.sql %name%
script.sql:
--A whole bunch of formatting code
...
spool T:\&1.csv
SELECT * FROM tablename WHERE somecol='&1';
spool off
exit
Furthermore, if I change the sqlscript to read:
spool T:\'&1'.csv
My output file becomes 'TEST'.csv. When I leave out the single quotes, why does it delete the '.' in the spool file name and append '.LST'?
Note that the parameter being passed to the script is also being used in the query without any issues.
I've also tried passing the arguments using sqlcmd utility, but no luck there, so I'd like to get this working without sqlcmd if possible. For now, I can rename the file, but it is a bit annoying to have to do that every time I need to run the script.
Found the following that answered my question when searching for another issue. Variable names must be terminated with a '.' to properly concatenate the variable and surrounding string. http://www.orafaq.com/node/515
Now, what if I want to prompt for the user's name, like Fred, and set the prompt to FredPrompt> ? Simply stuffing the variable in there won't do:
MyPrompt> set sqlp '&EnterNamePrompt> '
Enter value for enternameprompt: oops
oops>
And neither will concatenating, since SQL*Plus doesn't accept concatenation for the values passed to its SET commands:
oops> set sqlp '&EnterName' || 'Prompt> '
Enter value for entername: fred
SP2-0158: unknown SET option "||"
fred
The power user tip to remember here is that variable names can be terminated by a period. Simply tuck a period between your variable name and the succeeding text:
SQL> set sqlp '&EnterName.Prompt> '
Enter value for entername: Fred
FredPrompt>

MySQL LOAD DATA INFILE with PostgreSQL COPY FROM command

I am very new to PostgreSQL. Actually I was using MySQL before but for some project specific reason I need to use postgreSQL and do a POC.
Now the problem is:
I was using MySQL LOAD DATA INFILE command to load the column content from a file to my database table.
My table structure is :
Table name: MSISDN
Table Column Names: ID(primary key - auto_generated), JOB_ID, MSISDN, REGION, STATUS
But my input text file(rawBase.txt) is having only below columns:
MSISDN, REGION
so I was using the below command to load these above 2 column with initial JOB_ID and STATUS.
LOAD DATA INFILE 'D:\\project\\rawBase.txt' INTO TABLE MSISDN
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(MSISDN,REGION)
SET JOB_ID = 'XYZ1374147779999', STATUS = 0;
as you can see that there is a option available in LOAD DATA INFILE command where I can SET a particular initial value for the columns which are not present(JOB_ID and STATUS) in the input text file.
NOW,
in case of postgreSQL, I want same thing to happen.
There is also a same kind of command available COPY FROM
like below:
COPY MSISDN FROM 'D:\\project\\rawBase.txt' WITH DELIMITER AS ','
but I am not able to SET a particular initial value for the rest columns which are not present(JOB_ID and STATUS) in my input text file. I am not getting any fruitful example of doing this.
Please give some suggestion if possible.
Regards,
Sandy
You may do it the "Unix way" using pipes:
cat rawbase.txt | awk '{print $0",XYZ1374147779999,0"}' | psql -d dbname -c "copy MSISDN FROM stdin with delimiter AS ','"
Now from the file paths in the question it appears you're using MS-Windows, but a Unix shell and command-line tools like awk are available for Windows through MSYS or Cygwin.
COPY with a column-list, and set a DEFAULT on the table columns you don't specify.
regress=> CREATE TABLE copydemo(a text not null, b text not null default 'blah');
regres=> \COPY copydemo(a) FROM stdin
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> blah
>> otherblah
>> \.
regres=> SELECT * FROM copydemo;
a | b
-----------+------
blah | blah
otherblah | blah
(2 rows)
You're probably COPYing from a file rather than stdin; I just did it on stdin for a quick demo of what I mean. The key thing is that columns that require values not in the CSV have DEFAULTs set, and you specify a column-list in COPY, eg COPY (col1, col2).
There is unfortunately no equivalent to the COPY-specific SET that you want there. You can stage via a temporary table and do an INSERT INTO ... SELECT, as Igor suggested, if you can't or don't want to ALTER your table to set column DEFAULTs.

SSIS 2008 pb with file system task to delete a file

in my foreach loop container, I would like to delete the current processed file.
I try as follows, but no file is deleted at the end, any idea??
Here is the property of my loop , Current processed file comes from FileNameSimu variable
I would like to delete the current file
Make sure that the value in the variable User::FileNameSimu contains the file path like C:\Folder1\SubFolder2\File.txt and not just the file name File.txt
Please note the description of the property SourceVariable on File System Task. It expects a path.
On the Variables window, select the variable FilePath and press F4 to view the properties of the variable. Change the property EvaluateAsExpression to True and set the value #[User::Directory] + #[User::FileName] to the property Expression assuming that your variable Directory contains the folder path and the variable FileName contains the name. Make sure that the variable Directory ends with a backslash at the end like C:\temp\ and not like C:\temp. If it doesn't have a backslash at the end change your expression to #[User::Directory] + "\\" + #[User::FileName]
Or use the backslash in the expression