redirect output of sql to file in unix - 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

Related

Masscan, scan multiple ranges from txt file

I have txt file with
x.x.x.x/22
x.x.x.x/23
x.x.x.x/24
Etc etc etc
How can i get masscan to read these ranges, and perform a scan on all of them ?
sudo masscan -p80 -iL file_name.txt
You can customise your port number. The scan must be run in the same directory where you created your text file.
scan output-
enter image description here

Assign HDFS location of Hive external table to a Unix variable

Is there a way to get hdfs location from external table and assign to unix variable.
Yes, there is a way.
Run a command like the below,
export location=hive -e "SHOW CREATE TABLE <dbname.tablname>;"| grep hdfs://
Please use after the equal sign on the above command and at the end. It is not shown here due to Stackoverflow's rich text format.
You can check the variable like the below,
echo $location
'hdfs://hostname:8020/HDFS/PATH/OF/THE/TABLE'
Hope this helps!

How to handle a file having header in between the records after removing duplicates from the file

We have a file which has been processed by unix command for removing duplicates. After the de-duplication new file has the header in-between the records. Please help to solve this and thanks in advance for inputs.
Unix Command : Sort -u >
I would do something like this:
grep "headers" >output.txt
grep -v "headers" >>output.txt
The idea is the following: first take the headers and put them into output.txt, and afterwards take everything which is not a header and put it into that output file.
First you need to put the information in the output file (which means you need to create the output file, hence the single > character), secondly you need to append the information to the already existing output file (hence the double >> character).

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

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

Unix: prepending a file without a dummy-file?

I do not want:
$ cat file > dummy; $ cat header dummy > file
I want similar to the command below but to the beginning, not to the end:
$ cat header >> file
You can't append to the beginning of a file without rewriting the file. The first way you gave is the correct way to do this.
This is easy to do in sed if you can embed the header string directly in the command:
$ sed -i "1iheader1,header2,header3"
Or if you really want to read it from a file, you can do so with bash's help:
$ sed -i "1i$(<header)" file
BEWARE that "-i" overwrites the input file with the results. If you want sed to make a backup, change it to "-i.bak" or similar, and of course always test first with sample data in a temp directory to be sure you understand what's going to happen before you apply to your real data.
The whole dummy file thing is pretty annoying. Here's a 1-liner solution that I just tried out which seems to work.
echo "`cat header file`" > file
The ticks make the part inside quotes execute first so that it doesn't complain about the output file being an input file. It seems related to hhh's solution but a bit shorter. I suppose if the files are really large this might cause problems though because it seems like I've seen the shell complain about the ticks making commands too long before. Somewhere the part that is executed first must be stored in a buffer so that the original can be overwritten, but I'm not enough of an expert to know what/where that buffer would be or how large it could be.
You can't prepend to a file without reading all the contents of the file and writing a new file with your prepended text + contents of the file. Think of a file in Unix as a stream of bytes - it's easy to append to an end of a stream, but there is no easy operation to "rewind" the stream and write to it. Even a seek operation to the beginning of the file will overwrite the beginning of with any data you write.
One possibility is to use a here-document:
cat > "prependedfile" << ENDENDEND
prepended line(s)
`cat "file"`
ENDENDEND
There may be a memory limitation to this trick.
Thanks to right searchterm!
echo "include .headers.java\n$(cat fileObject.java )" > fileObject.java
Then with a file:
echo "$(cat .headers.java)\n\n$(cat fileObject.java )" > fileObject.java
if you want to pre-pend "header" to "file" why not append "file" to "Header"
cat file >> header
Below is a simple c-shell attempt to solve this problem. This "prepend.sh" script takes two parameters:
$1 - The file containing the pre-appending wording.
$2 - The original/target file to be modified.
#!/bin/csh
if (if ./tmp.txt) then
rm ./tmp.txt
endif
cat $1 > ./tmp.txt
cat $2 >> ./tmp.txt
mv $2 $2.bak
mv ./tmp.txt $2

Resources