Supressing error while using grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Supressing error while using grep command
# 1  
Old 03-20-2012
Supressing error while using grep command

I am tryin to grep some pattern in file and redirecting it in to another file. If the file doesn't exist then it should not throw error.

Code:
eg : grep "pattern" "$path1/filename" >> newfile

I have multiple number of grep statement like this. so i cant check each and every is exist or not... Please help me in this

Last edited by methyl; 03-20-2012 at 07:49 AM.. Reason: please use code tags
# 2  
Old 03-20-2012
Code:
grep "pattern" "$path1/filename" >> newfile 2> /dev/null

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

2. Shell Programming and Scripting

Grep command error

I am using a command but getting an error despite of modifying it many times. Pattern=`grep story file|cut -c 19-24` Where as 'story' is the pattern to be matched and i want to cut the value of characters ranging from 19 to 24 when this pattern is found in a variable. file consists of below... (11 Replies)
Discussion started by: pratima.kumari
11 Replies

3. Shell Programming and Scripting

Supressing lines starting with #

Ok, I should know how to do this... I want to run crontab -l and pipe it through sed so that only those lines that do not have a # as the first character show on the screen... I know Ive doen this before but its been a decade since I scripted anything Im working in AIX 7.1 using the crontab... (3 Replies)
Discussion started by: immagikman
3 Replies

4. Shell Programming and Scripting

Help with using grep command with copy command

Hi, im taking an entry Unix class, and as part of my lab assignment I have to copy all files in the /home/david/lab3 directory that have the file extension .save to your lab3/temp directory. I'm having trouble getting the grep to do anything worth while I've been trying to do: cp... (6 Replies)
Discussion started by: Critical jeff
6 Replies

5. Shell Programming and Scripting

Help supressing spool output from screen when calling sqlplus from script

I'm calling an embedded sql from my shell script file. This sql does simple task of spooling out the contents of the table (see below my sample code) into a spool file that I specify. So far so good, but the problem is that the output is also displayed on screen which I do NOT want. How can I... (3 Replies)
Discussion started by: MxC
3 Replies

6. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

7. Shell Programming and Scripting

supressing carrige returns/line feeds

Hi gurus I am stripping lots of email addresses from a file with this grep "^To" file.log |awk '{print "1,"$2}' > recipients.out file.log looks something like this: oasndfoasnosf To: person@email.co.uk lsdfjosd sdlfnmsopdfwer dtlghodrgn To: person2@emailsss.com sldfnsdf I... (5 Replies)
Discussion started by: terry2009
5 Replies

8. Shell Programming and Scripting

Supressing and replacing the output of a field in Awk

Wondering if anybody can help with changing the output of a field. I'm needing to change the output of a field in this file: User Process ID Time Active Licences Type ChangeAdmin (Phys-agsdev/19353 212), start Wed 1/21 6:30 (linger: 1800) u414013 (Phys-agsdev/19353 1491), start Wed 1/21 12:54... (5 Replies)
Discussion started by: Glyn_Mo
5 Replies

9. UNIX for Advanced & Expert Users

how to exclude the GREP command from GREP

I am doing "ps -f" to see my process. but I get lines that one of it represents the ps command itself. I want to grep it out using -v flag, but than I get another process that belongs to the GREP itself : I would like to exclude # ps -f UID PID PPID C STIME TTY TIME CMD... (2 Replies)
Discussion started by: yamsin789
2 Replies

10. UNIX for Dummies Questions & Answers

supressing kernel info in /bin/login

I'm assuming that /bin/login is the culprit that keeps on displaying my kernel version when I telnet in, as I have already killed /etc/issue.net, and /etc/motd (although motd is displayed after login), but I now still get my kernel version. I want a "clean" login, *NO* versions of anything... (3 Replies)
Discussion started by: cerberusofhate
3 Replies
Login or Register to Ask a Question