use content of a file as subject with mailx in informatica PC - unix

I am using a mailx command in informatica powercenter command task. Requirement is to use the content of a file that gets generated with every workflow run, as subject of the email. Issue is subject is a sentence and my command captures only the first word in that sentence stopping at the space. How to overcome this? Is there an alternate way to achieve this?
Sample content of the subject file that gets generated is something like this:
testSub="Today is Saturday"
command used in the command task:
. /Targetdirectory/subject.txt; cat /Targetdirectory/Filename.txt |mailx -s $testsub xxx.zzz#gmail.com
When I receive the email, subject shows up as "Today"
Thanks

Put $testSub in quotes.
. /Targetdirectory/subject.txt; cat /Targetdirectory/Filename.txt |mailx -s "$testsub" xxx.zzz#gmail.com

Related

How to remove empty/blank space while retrieving a value from an input file in unix

I'm writing a script in which I need to retrieve input parameters for the script from a text file. There are around 10 such input parameters to be retrieved. The input file is actually retrieved from a tool with customer details in description, hence it comes in any format. Sometimes there comes an empty space or blank space after or before the title.
For example:
Consider the customer details as below
Name: Divya
Email: divyaapinky#gmail.com
And I'm doing the below in my script
name=`grep -i name input_file.txt | awk -F":" '{print $2}'`
echo $name
The above gives me the name with a space " Divya"
The above has some space in after the colon, so when I'm trying to retrieve the name or email address, it's giving space as well. Please note, that I have to use colon only as delimiter and not space as not every field has space, it depends on how customer provides the details.
Could you please suggest me a command to do this?
You can use the sed command to get your desired output. Please find below the command which might help you.
sed s/^ *//g
I see the grep a bit problematic: what happens if 'name' is part of the email address? A better solution would be:
INPUTFILE="input_file.txt"
NAME=`grep -i "^name:" "${INPUTFILE}" | sed 's/^name:[ \t]*//; s/[ \t]*$//'`
echo "${NAME}"
That greps "name:" only at the beginning of a line and eliminates leading and trailing spaces and tabs.

redirect output of sql to file in unix

I need to run a stored proc and redirect its output to a text file. Right now I am using the below command to do it, but in the text file I have the headers and also the columns are separated by spaces. I need the output file to start with the first row of data and no spaces between the columns. Can someone please advise how to do this?
Thanks!
Command:
isql -S <server>-U <user>-P <password> -w1024 << EOB1 >> <text file>
use <db_name>
go
exec <proc>
go
EOB1

Splitting a unix file in shell script

I have a file xyz1.sh with the content below with when i do cat xyz1 i get the result:
`$echo "Welcome to the server"
Welcome to the server
$echo "Hi this is content in the test file1."
Hi this is content in the test file1.
$ls
abc.txt
$date
17 October 2016`
I aim to generate a new file xyz2 with only the shell commands. Is there any efficient way to achieve this apart from searching the xyz1 for some specific set of commands. Can there be any way to identify for all unix commands and get the lines out from the file?
xyz2 having content:
`$echo "Welcome to the server"
$echo "Hi this is content in the test file1."
$ls
$date`
TIA
You can use the Unix sed command to process the file. The following command
deletes every line that matches the given regular expression, /^[^$]/ (which finds every line that does not being with a $). The output is then redirected to create the new file xyz2.
sed '/^[^$]/d' xyz1.sh > xyz2

Is it possible to use wild characters to delete dataset on z/OS

I want to remove lots of temporary PS datasets with dataset name like MYTEST.**, but still can't find an easy way to handle the task.
I meant to use a Shell command below to remove them
cat "//'dataset.list'"| xargs -I '{}' tsocmd "delete '{}'"
However, first I have to save the dataset list into a PS dataset or Unix file. In Unix, we can redirect output of ls command into a text file: "ls MYTEST.* > dslist", but on TSO or ISPF panel, seems no simple command to do that.
Anyone has any clue on this? Your comment would be appreciated.
Rexx ISPF option is probably the easiest and can be used in the future, but options include:
Use the save command in ispf 3.4 to save to a file, then use a rexx program on the file created by the save command
listcat command, in particular
listcat lvl(MYTEST) ofile(ddname)
then write a rexx program to do the actual delete
Alternatively you can use the ISPF services LMDINIT, LMDLISTY & LMDFREE in a rexx program running under ISPF i.e.
/* Rexx ispf program to process datasets */
Address ispexec
"LMDINIT LISTID(lidv) LEVEL(MYTEST)"
"LMDLIST LISTID("lidv") OPTION(list) dataset(dsvar) stats(yes)"
do while rc = 0
/* Delete or whatever */
end
"LMDFREE LISTID("lidv")"
For all these methods you need to fully qualify the first High level qualifier.
Learning what Rexx / ISPF will serve you into the future. In the ISPF Editor, you can use the model command to get Templates / information for all the ISPF commands:
Command ====> Model LMDINIT
will add a template for the lmdinit command. There are templates for rexx, cobol, pl1, ISPF-panels, ISPF-skeletons messages etc.
Thanks Bruce for the comprehensive answer. According to Bruce's tips, I just worked out a one-line Shell command as below:
tsocmd "listcat lvl(MYTEST) " | grep -E "MYTEST(\..+)+" | cut -d' ' -f3 | xargs -I '{}' tsocmd "delete '{}'"
Above command works perfectly.
Update - The IDCAMS DELETE command has had the MASK operand for a while. You use it like:
DELETE 'MYTEST.**' MASK
Documentation for z/OS 2.1 is here.

In what order does cat choose files to display?

I have the following line in a bash script:
find . -name "paramsFile.*" | xargs -n131072 cat > parameters.txt
I need to make sure the order the files are concatenated in does not change when I use this command. For example, if I run this command twice on the same set of paramsFile.*, parameters.txt should be the same both times. My question is, is this the case? And if it isn't, how can I make sure it is?
Thanks!
Edit: the same question goes for xargs: would that change how the files are fed to cat?
Edit2: as William Pursell pointed out, this question is actually about find. Does find always return files in the same order?
From description in man cat:
The cat utility reads files sequentially, writing them to the standard
output. The file operands are processed in command-line order.
If file is a single dash (`-') or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it
and
then reads it until EOF. This complements the UNIX domain binding capability available in inetd(8).
So yes as long as you pass the files to cat in the same order every time you'll be ok.

Resources