Read the file in UNIX without Using Unix Command (may be Datastage routine) - datastage

I have a file in a Unix path which has data like:
2019-06-21,2019-06-22|2019-06-22,2019-06-23
I want to read this date and pass this to User Variable Activity .
I am not allowed to Use ant Unix command to read the file.
I read some forum and found that it can be done by routine activity,but not sure where to write the routine and whats the routine name.
Can anyone help in this
* open FinaltestOut.txt
OPENSEQ /home/shivam : '\' : FinaltestOut.txt TO H.FinaltestOut.txt THEN
CALL DSLogInfo("******************** File " : FinaltestOut.txt : " opened successfully", "JobControl")
END ELSE
CALL DSLogInfo("Unable to open file", "JobControl")
ABORT
END
READSEQ FinaltestOut.txt.RECORD FROM H.FinaltestOut.txt ELSE
Call DSLogWarn("******************** File is empty", "JobControl")
END
firstline = Trim(FinaltestOut.txt.RECORD[1,32]," ","A") ******* will read the first 32 chars
Call DSLogInfo("******************** Record read: " : firstline, "JobControl")
CLOSESEQ H.FinaltestOut.txt

Step 1 : You can use execute command activity to cat this File.
Step 2 : Then use User Variable activity to get the execute command output.
Step 3 : Use Field function inside the UV activity to get the desired field.
Note : Here we just use cat command that too in execute command activity. Its the easy approach to resolve your issue.

Related

Weechat add hook command in every send Messages

I am a new user in Weechat. I have made a customized weechat script from another existing script. To run that script I need to use hook command every time i send text to channel . For example /myhook message_to_channel . I want to automate this process so every time I send messages to a channel i wouldn't need to write /myhook but just message_to_channel . Is there any way I could make it happen. Thanks.
The alias plugin that is included in WeeChat by default can facilitate this.
You can run the following command to create the alias you want.
/alias add message_to_channel /myhook message_to_channel
After that, you should be able to just use /message_to_channel. You can also add arguments if you like:
$n: argument 'n' (between 1 and 9)
$-m: arguments from 1 to 'm'
$n-: arguments from 'n' to last
$n-m: arguments from 'n' to 'm'
$*: all arguments
$~: last argument
$var: where "var" is a local variable of buffer (see /buffer localvar)
examples: $nick, $channel, $server, $plugin, $name
The documentation is here.

How do I retrieve the filename of the current script in AutoHotkey?

I would like to retrieve the filename of the currently running script in AutoHotkey and save it to a variable.
For example, if my script were named sample-script.ahk, I would like to display a message saying "The current script is sample-script.ahk".
How do I retrieve the filename of the currently active script in AutoHotkey?
Use: A_ScriptName The filename of the current script, without its path, e.g. MyScript.ahk.
MsgBox, The current script is %A_ScriptName%
See: https://autohotkey.com/docs/Variables.htm#BuiltIn
and more particularly, https://autohotkey.com/docs/Variables.htm#ScriptName

Greenplum : Getting filenames processed via an external table

we are processing multiple files using external table. Is there any way I can get the file name being processed in external tables and stored it in database table?
Only workaround I can find is appending the file name to every record in the flat file which isn't ideal when huge dataset and multiple files.
Can anyone help on this
Thanks
No, the file name is simply never passed from the gpfdist daemon back to Greenplum. So you have to append the file name to each line - you can use gpfdist transformation for doing so
I was struggling with this as well, here's my solution. Please note I'm not an expert in linux, so there may be a one liner solution.
So I wanted to add a filename column in front of my records.
That can be done in sed, I've created a transform.sh file, with the following content:
#/bin/sh
filename=$1
#echo $filename >> transform.txt
sed -e "s|^|$filename\v|" $filename
Please note that I was using vertical tab as a delimiter, \v. Also in the filename you could have / hence using | . In order to have the value of $filename we have to use double quites for sed.
Test it, it looks good.
./transform.sh countersamples-2016-03-02--11-51-10.csv
countersamples-2016-03-02--11-51-10.csv
timestamp
machine
category
instance
name
value
countersamples-2016-03-02--11-51-10.csv
2016-03-02 11:51:10.064
DESKTOP-4PLQKVL
Memory
% Committed Bytes In Use
74.8485488891602
This part is done, lets continue with gpfdist. We need a yaml file that can be passed to gpfdist, I named this transform.yaml
Content:
---
VERSION: 1.0.0.1
TRANSFORMATIONS:
add_filename:
TYPE: input
CONTENT: data
COMMAND: /bin/bash transform.sh %filename%
Please note that we have the %filename% value here. It seems that gpfdist prefilters the files that needs to be handled, and passes them 1 by 1 to our transform.
Lets fire up gpfdist:
gpfdist -c transform.yaml -v
Now go into greenplum and create an external table such as:
CREATE READABLE EXTERNAL TABLE "ext_transform"
(
"filename" text,
"timestamp" timestamp without time zone ,
"machine" text ,
"category" text ,
"instance" text ,
"name" text ,
"value" double precision
)
LOCATION ('gpfdist://localhost:8080/*/countersamples*.csv#transform=add_filename')
FORMAT 'TEXT'
( HEADER DELIMITER '\013' NULL AS '\\N' ESCAPE AS '\\' )
And when we select data from it:
select * from "ext_transform";
We see:
I've created 2 folders to see how it reacts if the files are not in the same folder as the transform. This way I can distinguish between the 2 files, even if their data is identical.

same input for interactive command in Perl script

In Perl script I am using command of unit(external command) using system
but that command need some run time input from user. Every time I want to give similar input which is stored in variable.
My command is:
system("dt ci $dest_file");
after this command my script is waiting for user input,
lets say I want to give "re base" as input to this every time
How can I give fix input every time it asks?
Please help, I am working on windows 7.
I want to make script completely automated... it should not wait for user input
If you call your script like this:
perl test.pl < input.txt
It should take the content of the file as an input. ( this is working with STDIN read )

opening a batch file that opens a text file in python

I am writing a script that can execute a batch file, which needs to open a file in the same folder first. My current code is:
from subprocess import Popen
p = Popen("Mad8dl.bat <RUNTHISTO.txt>", cwd=r"C:\...\test")
stdout, stderr = p.communicate()
where the ... is just the path to the folder. However, everytime I run it I get the syntax error:
The syntax of the command is incorrect
Any help regarding the syntax would be greatly appreciated.
First, you should probably remove the < and > angle brackets from your code; just pass the filename, without any brackets, to your batch file. (Unless your filename really does contain < and > characters, in which case I really want to know how you managed it since those characters are forbidden in filenames in Windows).
Second, your code should look like:
from subprocess import Popen, PIPE
p = Popen(["Mad8dl.bat", "RUNTHISTOO.txt"], cwd=r"C:\...\test", stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
Note the list containing the components of the call, rather than a single string. Also note that you need to specify stdout=PIPE and stderr=PIPE in your Popen() call if you want to use communicate() later on.