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
# 1  
Old 06-16-2008
how to redirect 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 inside.

can anyone help me out with this.

eg: grep -v 'rows' GREP_FILE > GREP_DEST

when i am trying this in the unix prompt i am getting the required output like the GREP_DEST file will have an output with all the lines having 'rows' removed.

when i am giving the same command inside my shell script, its not working..

thanks in advace for all your help..
# 2  
Old 06-16-2008
# 3  
Old 06-17-2008
hi,

i tried giving the full path as well... but still not working.. even i wanted to use 'awk' command like this... redirecting the output to some other file.. that also wasnt working... but working outside in the unix prompt..

please help me.. its urgent.. Smilie

thanks,
kripa.
# 4  
Old 06-17-2008
Bug try this way ..redirect the output of a grep command to a file inside a shell script

try like this
create the file which is used to load

touch first
grep -il grep * > first


if the extracting file is located in some other path then
specify the exact path
# 5  
Old 06-17-2008
What is the error..?

What is the error you are getting , when you use it in script. Post your script here, that would help everyone to give you the solution.
# 6  
Old 06-17-2008
How exactly are you putting this into a script? Does the first line read #!/bin/sh and the second line contain this command, and nothing else? If not, can you try this simple script, just to set a baseline for us, and report back?
# 7  
Old 06-17-2008
hi kamalesh,

i tried that grep command.. but can you say me what the option -il is about... actually.. what i am tying to do is that, i am formatting some file and the contents of the file i am passing it as a parameter to an sql query..

so, i will be connecting to sqlplus and i am executing the query.. the output of which i am getting in some file.. and i want to remove the last line in the sql query like "24 rows selected" etc from this file .so for that i am using grep -v option. and here i am trying to redrect the output to a file where i am stuck..

also i want to use the spool command ..to spool this output of the sql query and to create a .lst file.. where i am again stuck..Smilie

thanks for the great help..
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