View ouput as a file

Hi all ,

I have a view in teradata , the ouput of that view have to be stored as a file with delimitere as '|'.Is there any possibility of doing this in unix ?

Thanks in advance ,
Vinoth

Can you give a sample input and output you are expecting.....

I dont have any sample file with me right now . From the view , i will get the output as a table.I have to extract the data from the table and then have to write it in the file .

sample input(TABLE)

col1    col2    col3 
 12      14       15
 34       13       23 

Expected result(FILE)

12|14|15
34|13|23
sed "s/^ *//;s/ *$//;s/ \{1,\}/|/g" inputfile > outputfile.txt

The above should work

Try:

awk '{$1=$1}1' OFS="|" infile

or

awk '{$1=$1}NR>1' OFS="|" infile

to lose the header..

Hi Scrutinizer
can you please explain

awk '{$1=$1}1' 

.
i am new to awk, how does the above code work...

Thanks!!!!

Hi raghu, in awk, if any of the fields ($1, $2 etc) gets a new value the enitre record (in this case a line) gets recalculated and the output field separator is applied so that it now contains "|" instead of tabs or spaces. After the brackets the "1" ensures that the recalculated records get printed..

1 Like