Question about the here tag


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about the here tag
# 1  
Old 08-13-2008
Question about the here tag

Hello,

Can you tell me why the last command(echo) in this script does not execute?
In the command line I have to hit control -d to terminate this tag but I dont know how to do it in a shell script.

Code:
sqlplus -s <<EOF
 connect / as sysdba
 select sysdate from dual;
 quit;
 EOF

echo "other things to do"

# 2  
Old 08-13-2008
The EOF tag needs to be flush with the left margin. I often use __EOF with some leading underscores to make the indentation look the way I like.

Code:
sqlplus -s <<'__EOF'
  connect / as sysdba
  select sysdate from dual;
  quit;
__EOF

echo "other things to do"

# 3  
Old 08-13-2008
Thank you. Do you also know how to redirect this output to a file or pipe it?

Because when I try with "> file" it just contunues to ask for new imput.
# 4  
Old 08-13-2008
I don't understand your question, but maybe a bunch of examples can help.

Code:
vnix$ cat <<HERE | wc
two words
make that five
HERE
      2       5      25
vnix$ nl <<HERE | sed 's/no//' >/tmp/ovtpvt
foo no line numbers
HERE
vnix$ cat /tmp/ovtpvt
     1	foo  line numbers
vnix$ cat <<HERE >/tmp/song.txt
I'm a ${work} and I'm $adjective
HERE
vnix cat /tmp/song.txt
I'm a Lumberjack and I'm okay

... the last example of course assuming you have set the environment variables $work and $adjective correctly. (-:
# 5  
Old 08-13-2008
What I'm after is something like this(which does not work of course):


Code:
sqlplus -s <<'__EOF'
  connect / as sysdba
  select sysdate from dual;
  quit;
__EOF >> file_to_output.txt # (or | awk something...)


So I need the output of this (not necessary in a file) in order to process it in the script.
# 6  
Old 08-13-2008
try to execute below to direct the output; might this will help you.

db_date=`sqlplus -s / <<EOF
select sysdate from dual;
EOF
`
echo $db_date>> file_to_output.txt
# 7  
Old 08-13-2008
Yes, but the query I'm giving will be more complex and will output many rows.

The "echo $var" will suppress all of them in only one row.

I need a way to output the result as it is displayed on the console.


LE: Actually I may have found a way but cant test it right now as I dont have access to an sqlplus

Maybe something like this will work?

Code:
$~ sort > tempfile  <<'EOF'
field2
field1
EOF

$~ cat tempfile 
field1
field2


Last edited by majormark; 08-13-2008 at 03:00 PM..
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