Question about the here tag


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about the here tag
# 8  
Old 08-13-2008
To send output to a file...
Code:
sqlplus -s <<'__EOF' >> output_file.txt
  connect / as sysdba
  select sysdate from dual;
  quit;
__EOF

To pipe it to a command...
Code:
sqlplus -s <<'__EOF' | awk '{print}'
  connect / as sysdba
  select sysdate from dual;
  quit;
__EOF

# 9  
Old 08-14-2008
It works, thank you.

One more question about this tag:

How can I make this variable substitution inside EOF?
$newv and ${newv} are interpreted literally

Code:
for i in `cat textfile`
do

newv="ALTER SYSTEM KILL SESSION '$i' IMMEDIATE;"

sqlplus -s <<'EOF'
connect / as sysdba
$newv
quit
EOF

done

output is:
SP2-0042: unknown command "$newv" - rest of line ignored.

# 10  
Old 08-14-2008
As illustrated by the examples I posted, all it takes is removing the single quotes around EOF.

As an aside, the cat in backticks is an anti-pattern.

Code:
while read i; do
  newv="ALTER SYSTEM KILL SESSION '$i' IMMEDIATE;"
  sqlplus -s <<____EOF
    connect / as sysdba
    $newv
    quit
____EOF
done <textfile

# 11  
Old 08-14-2008
Thank you very much era Smilie
# 12  
Old 08-14-2008
Try bracketing the whole lot with parentheses.

(
sqlplus -s <<EOF
connect / as sysdba
select sysdate from dual;
quit;
EOF
) 2>&1 | awk_or_whatetever_pipeline > my_filename
# 13  
Old 08-14-2008
... if you for some weird reason can't bring yourself to use the correct syntax which was posted earlier.

Code:
sqlplus -s <<EOF | awk_or_whatever_pipeline >my_filename
  dit dit dah
EOF

# 14  
Old 08-14-2008
You can mix and match the various redirect options in shell. For example if you want to run two sqlplus sessions, filter each one and output the final results to a file.

(
sqlplus -s <<EOF | awk_or_whatever_pipeline_one
dit dit dah
EOF

sqlplus -s <<EOF | awk_or_whatever_pipeline_two
dit dit dah
EOF
) 2>&1 >my_filename


Back to the point. In Oracle you may wish to check that v$session is current before issuing the kill. Don't forget to escape v\$session if it's mentioned in a unix shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

3. Shell Programming and Scripting

Find a tag with data and replace its data in another tag

Hi I have one file, :16R::GENL :20C::RELA//SET//ABC123456 :22F::XYZYESR :20C::MITI//NETT/QWERTY12345 :16S::GENL :16R::GENL :20C::RELA//SET//XYZ23456 :22F::XYZYESR :16S::GENL The requirement is, if :20C::MITI// is present in any block, then replace the data of :20C::MITI// in... (8 Replies)
Discussion started by: Soumyadip Dutta
8 Replies

4. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

5. Shell Programming and Scripting

XML Parse between to tag with upper tag

Hi Guys Here is my Input : <?xml version="1.0" encoding="UTF-8"?> <xn:MeContext id="01736"> <xn:VsDataContainer id="01736"> <xn:attributes> <xn:vsDataType>vsDataMeContext</xn:vsDataType> ... (12 Replies)
Discussion started by: pareshkp
12 Replies

6. Shell Programming and Scripting

Search for a html tag and print the entire tag

I want to print from <fruits> to </fruits> tag which have <fruit> as mango. Also i want both <fruits> and </fruits> in output. Please help eg. <fruits> <fruit id="111">mango<fruit> . another 20 lines . </fruits> (3 Replies)
Discussion started by: Ashik409
3 Replies

7. Shell Programming and Scripting

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

8. OS X (Apple)

Uniq tag

Hello, I have recently imported all my scripts into OS X. There is one unix command that is problematic in the new environment: sort temp7.txt | uniq -u -w4 > temp8.txt The system doesn't seem to like the -w tag. Is there an alternative command? Here is the objective: Data: 1234 aaa... (1 Reply)
Discussion started by: palex
1 Replies

9. Shell Programming and Scripting

sed, awk [TAG]$content[/TAG] How to get var in $content in textfile?

Hello, I got a Qstion. Im posting to a phpbb forum with bash and curl.. i have a text file with the following tags that i post to the forum: $var1 $var2 $var3 How can i with sed or awk put var content from shell script between the ... in the... (7 Replies)
Discussion started by: atmosroll
7 Replies

10. Shell Programming and Scripting

print all the rows from "BUY" Tag with "SELL" with Buy/sell tag at end

hi I have the following input and i want to print all the rows from "BUY" Tag till "SELL" alongwith Buy/sell tag at end of each row ------ INPUT ===== 30/06/2009,NORMAL,ALL,ALL BUY 1,CBLO/020709,T+0,30/06/2009,100.00,3.00,999835643.46,200906300000422,-, 15:04:42,BUY... (5 Replies)
Discussion started by: r_t_1601
5 Replies
Login or Register to Ask a Question