how to redirect the output of a grep command to a file inside a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to redirect the output of a grep command to a file inside a shell script
# 8  
Old 06-17-2008
hi nua7,

thanks for the interest..

actually i am not getting any error.. when i am trying to execute the command, its creating the output file but not redirecting ...means a zero byte file will be created..

also, i am connectin to sqlplus in between.. and am getting the output of th sql query and am using the grep command to format that file... which i am unable to do..

also, can anyone help me by saying how can i spool a file.. i just know that i need to use spool on and spool off commands to do that.. but then where will i be gettnig the output .lst file..

thanks,
Krips.
# 9  
Old 06-17-2008
hi era,

i tried using a simple shell script as you said where i just gave this much :

#!/bin/sh

grep -v 'row' /path/filename > /path/output_filename


here i am getting the output perfectly...
but in the previous shell script where i encountered the problm, i was connecting to sqlplus as well..
thern i used something like this

echo 'select STATEMENT' > sql.sql
echo 'quit' >> sql.sql

and i am sqlplus that will run this sql.sql for the particular database.. and getting the output in the specified file properly..

but after that , i was trying to remove the last line of the output of sql query like "24 rows selected" using grep command -

grep -v 'rows' $INPUT_FILE > $OUTPUT_FILE

where i am unable to get the output correctly..
can anyone help me out in finding exactly what may be the reason for this issue..

thnaks and regards,

Krips.
# 10  
Old 06-17-2008
hi,

can i know if i am using connecting sql plus properly or not..

as of now i am giving it like

sqlplus -s user/pass@db -i sql.sql -o sql.sql.01

in the sql.sql i am having the contents like this -

select STATEMENT
quit

the output of this select statement into sql.sql.01 ...
with this am i properly exiting out of the sqlplus??

in the grep command i will be using this sql.sql.01 file as its input..
hope you all got a better idea about wat i am trying to do.. i think, i am screwing up something with my sqlplus connection...is it so??

all your sugestions are appreciated...

thanks,

Krips.
# 11  
Old 06-17-2008
I'm guessing $INPUT_FILE is not set to what you think it's set to, or doesn't contain what you think it contains. How exactly are you generating the file, and assigning its name to a variable? Why aren't you pipiing the output through grep at the point when it is stored in a file in the first place? Or if it's always the last line you want to get rid of, try sed '$d'
# 12  
Old 06-19-2008
hi era,

the problem was with the sqlplus connection only.. even though i was getting the correct output then also, there was something wrong..

now i am able to connect to sqlplus properly and am getting the output correctly..thanks for all your help..

but am having one doubt regarding spool command. Will we be getting a .lst file by default as output of spool command.

eg : consider that i am giving the spool command like this..

spool /path/file
SQL QUERY
spool off;

i was said by someone that if we use spool command then by default we will be getting the output in a .lst file ..is it so? please go through the link also..
https://www.unix.com/shell-programmin...-spooling.html

hope you can clear my doubt..

thanks,

Krips.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect script output to file after grep

i have simple program that generate log file 1 line every sec, i need to do grep for specific record then redirect to another file. #!/bin/bash for i in `seq 1 20`; do echo $i sleep 1 done ./test.sh |egrep "5|10|15" 5 10 15 r ./test.sh... (2 Replies)
Discussion started by: before4
2 Replies

2. Shell Programming and Scripting

How to redirect the output of a command inside ftp block?

hi, i am using ftp to get files from remote server. inside the ftp i want to us ls -ltr command and send the output of it to a file. ftp -n remote_server <<_FTP quote USER username quote PASS password prompt noprompt pwd ls -ltr get s1.txt bye _FTP i... (4 Replies)
Discussion started by: Little
4 Replies

3. Programming

How to redirect the output of a shell script to a file?

hi, i have a html form which call a perl program, this perl program calls a shell script. <html> <head> <title>demo</title> </head> <body> <form name="frm1" action="/cgi-bin/perl_script.pl" method="post"> <input type="text" name="fname"> ... (1 Reply)
Discussion started by: Little
1 Replies

4. Shell Programming and Scripting

Shell Script to grep output from top command.

Hello, I want a script which would grep details from top command for specific processes. I m not sure of the PID of these processes but i know the names. $ top -c top - 16:41:55 up 160 days, 5:53, 2 users, load average: 9.36, 9.18, 8.98 Tasks: 288 total, 9 running, 279 sleeping, 0... (8 Replies)
Discussion started by: Siddheshk
8 Replies

5. Shell Programming and Scripting

Redirect the output in shell script for tftp

I've been using tftp in one of my file #!/bin/bash filename1="config1h.txt" filename2="config15.txt" hostname="test.com" tftp $hostname <</dev/null get $filename1 get $filename2 quit EOF My output looks like this # ./test3.sh tftp> Received 1262 bytes in 0.0 seconds tftp> Received... (2 Replies)
Discussion started by: LavanyaP
2 Replies

6. UNIX and Linux Applications

How to redirect grep command output to same file

Hi Everyone, Can anyone please tell me, how can I redirect the grep command output to same file. I am trying with below command but my original file contains no data after executing the command. $grep pattern file1 > file1 Kind Regards, Eswar (5 Replies)
Discussion started by: picheswa
5 Replies

7. Programming

Redirect input and output to a shell script?

Dear All: I am trying to do something that (I thought) was relatively straightforward, but my code snippet does not seem to work. Any suggestions? Thank you Sincerely yours Misha Koshelev #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include... (0 Replies)
Discussion started by: misha680
0 Replies

8. Shell Programming and Scripting

How redirect script output from inside of script?

Is it possible to redirect a script output by command inside of that script? I mean, if I have a script 'dosome.sh' I could run it by >dosome.sh > dosome.log I would dream to get some command inside of scrip to do the same; so, running the dosome.sh would have all output redirected to a log... (4 Replies)
Discussion started by: alex_5161
4 Replies

9. UNIX for Dummies Questions & Answers

how to get the output of a grep command to a file inside a shell script

hi, i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (1 Reply)
Discussion started by: kripssmart
1 Replies

10. Shell Programming and Scripting

Redirect grep output into file !!!!!

Hi, I am writing the following code in command prompt it is working fine. grep ',222,' SAPPCO_20080306.CSV_old > SAPPCO_20080306.CSV_new But the command is not working in the Shell Script... ########################################## #!/bin/sh #... (2 Replies)
Discussion started by: hanu_oracle
2 Replies
Login or Register to Ask a Question