Logparser - remove file extension - logparser

The below logparser query is returning the file names accessed from a website.
LogParser.exe -i:W3C "SELECT EXTRACT_FILENAME (cs-uri-stem) As FileName FROM c:\weblog\file1.log" -o:CSV
Example returned:
forum.aspx
example_image.jpg
search.aspx
Can someone provide insight on how to remove the extension of the file names from within logparser?

You can use the EXTRACT_PREFIX function to extract everything up to the last substring separated by '.':
SELECT EXTRACT_PREFIX( EXTRACT_FILENAME (cs-uri-stem), -1, '.')...

Related

SSIS Expression to append file extension

I'll get a Full filepath(FilePath and FileName) from a variable (#[User::V_FullPath]) as C:/Users/ABCD/Documents/Development/SampleFile.txt
I have a file with the same name but with .xlsx (SampleFile.xlsx) in another folder(A) that I want to copy to another folder(B)
To get just the filename I'm using the expression:
SUBSTRING(#[User::V_FullPath],37,47)
How can I append .xlsx to the above expression
My goal is to get SampleFile.xlsx
Why not just replace .txt with .xlsx?
REPLACE( #[User::V_FullPath]),".txt",".xlsx")
This will result in the following value:
C:/Users/ABCD/Documents/Development/SampleFile.xlsx
If you need only the filename Sample.xlsx, you can use TOKEN and TOKENCOUNT functions as follows:
TOKEN(TOKEN(#[User::V_FullPath],"/", TOKENCOUNT(#[User::V_FullPath],"/")), ".", 1) +".xlsx"
Expression result:
Sample.xlsx
Similar questions:
How do I extract file name from a path within an SSIS package?

using pattern while loading csv file from s3 to snowflake

below copy command is not working , please correct me if something wrong.
copy into mytable from #mystage pattern='20.*csv.gz'
here i am trying to load the files which are starts with 20, there are mix of files which are having the name as 2021myfile.csv.gz, myfile202109.csv.gz, above command is not loading any files though there are files which starts with 20.
if i use pattern as pattern='.*20.*csv.gz'`` it is taking all the files which is wrong, i need to load only the files that are starts with 20`.
Thanks!
This is because the pattern clause is a Regex expression.
Try this:
copy into mytable from #mystage pattern = '[20]*.*csv.gz'
Reference: Loading Using Pattern Matching

Stage command metadata$filename shows hundreds of occurences of single file

I have files in my stage that I want to query, as I want to include filenames in the result, I use the metadata$filename command.
My stage is an Azure ADLS GEN 2.
I have only one file matching the following regexp in my stage : .*regular.*[.]png.
When I run the command
SELECT
metadata$filename
FROM
#dev_silver_db.common.stage_bronze/DEV/BRONZE/<CENSORED>/S21/2715147 (
PATTERN => $pattern_png
)
AS t
I have 562 occurences of the same file in my result.
I thought that it was a bug from my IDE at first and double checked on Snowflake's history and this is the actual result from the request.
If I run LIST, the proper dataset (1 result only) is returned.
If I run the following command (the same with any union).
SELECT $pattern_png
UNION
SELECT
metadata$filename
FROM
#dev_silver_db.common.stage_bronze/DEV/BRONZE/<CENSORED>/S21/2715147 (
PATTERN => $pattern_png
)
AS t
I get the following result.
In my opinion, this behavior should be considered a bug, but I may have missed something.
For now I will just use TOP(1) because this is fine in my case but it may become a problem in other contextes.
Thank you in advance for your insights.
When you SELECT from a stage you are actually reading content of the file using a FILE FORMAT. When not specified CSV file format is used by default.
I think that what you're actually seeing is the metadata$filename information duplicated on every "row" that snowflake can read in your file.

Error on loading csv to SybaseIQ using dbisql

I am trying to upload a bunch of csv's to SybaseIQ using dbisql's Load command.
My CSV's look like this
"ps,abc","jgh","kyj"
"gh",""jkl","qr,t"
and my Load command and other options are these:
set temporary option ISQL_LOG = '/path/for/log/file';
set temporary option DATE_ORDER = 'MDY';
Load table test (a, b, c)
Format bcp
Strip RTRIM
Escapes OFF
quotes ON
Delimited by ','
I create a '.ctl' file like the one above and then execute it with the following command:
dbisql -c "uid = xxx; pwd = yyyy" -host aaaa - port 1089 -nogui test.ctl
On execution I get the following error:
Non-space text found after ending quote character for an enclosed field.
--(db_RecScanner.cxx 2473)
SQLCODE=-1005014, ODBC 3 state="HY000"
HOWEVER
It works fine with the following csv format
"ps,abc","jgh",kyj
"gh",""jkl",qrt
i.e if the last column doesn't have the double quotes it works. but all my files have double quotes around each element.
Also the following .ctl file
set temporary option ISQL_LOG = '/path/for/log/file';
set temporary option DATE_ORDER = 'MDY';
Load table test (a ASCII(8), b ASCII(7), c ASCII(7))
Strip RTRIM
Escapes OFF
quotes ON
Delimited by ','
is able to insert data as in the first csv sample into the database but it also inserts the quotes and the commas and also messes up the data:
ex: first row in the db would look like
"ps,abc" ,"jgh", "kyj""g
as opposed to
ps,abc jgh kyj
I am going nuts over trying to figure out what the issue is I have read the manual for sybase and dbisql and according to that the first control file should be able to load the data properly, but it doesn't do that. Any help on this will be appreciated. Thanks in advance
Also my table structure is like this:
a(varchar(8)) b(varchar(7)) c(varchar(7))

SQLite define output field separator on a single line command

I need to use a single command line to fetch a set of records from a database.
If I do this:
$ sqlite3 con.db "SELECT name,cell,email FROM contacts"
I get output with a separator "|", where the output looks like this:
Alison|+12345678|alison#mail.com
Ben|+23456789|ben#mail.com
Steve|+34567890|steve#mail.com
Is there a way (in single command line format like specified above) to change the output field separator to something else, like ";;;" or something else or more unique. This is because the output occasionally get the character "|" inside the records, and it causes issues.
My desired result is:
Alison;;;+12345678;;;alison#mail.com
Ben;;;+23456789;;;ben#mail.com
Steve;;;+34567890;;;steve#mail.com
Or any other unique separator, which is not likely to be found inside the values.
(The command is executed on a Linux machine)
Thank you.
The -separator option does what you want:
sqlite3 -separator ';;;' con.db "SELECT ..."
The only way to format the output so that you are guaranteed to not get the separator in the values is to quote all strings:
sqlite3 con.db "SELECT quote(name), quote(cell), quote(email) FROM contacts"
However, this would require you to parse the output according to the SQL syntax rules.

Resources