Redirect overwrites itself


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirect overwrites itself
# 8  
Old 05-21-2010
Hi.

See post #4 at https://www.unix.com/shell-programmin...rd-output.html

See http://kitenet.net/~joey/code/moreutils/ for code of the original utilities ... cheers, drl
# 9  
Old 05-21-2010
Quote:
Originally Posted by rlopes
I bet many people faced this problem before:

The command below will result in a blank file:

Code:
$ cat myfile | grep pattern > myfile

Is there any easy way to do it?
Not sure if this qualifies as "easy", but if you're the adventurous type:
Code:
(rm myfile; grep -v pattern > myfile) < myfile

I elaborate on how this works and the risks involved at the end of the post at https://www.unix.com/302407978-post5.html

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sendmail MX redirect

Hi I have a working sendmail setup for my domain, but would like to run a subdomain on another machine. I could try below, but its a production server and worry about messing it up. Hence the question. So I have machine names: mydomain.com (mail server) dev.mydomain.com currently the... (1 Reply)
Discussion started by: gtrava01
1 Replies

2. Windows & DOS: Issues & Discussions

gVim on windows 7 64 constantly overwrites symbolic and even hard links

I use sugarsync to sync my vimrc across computers. I keep the _vimrc file in a syncing folder and in my home folder, I have a symbolic link ~\_vimrc pointing to ~\Synced Docs\_vimrc. On my mac I have a .vimrc symbolic link pointing at the _vimrc file. On the pc side, every time I open the _vimrc... (3 Replies)
Discussion started by: dp88
3 Replies

3. Programming

pthread_mutex_trylock() overwrites global variable on CentOS5

Hi all, I am new to linux and got problem with pthread_mutex_trylock(). I have used mutex in my code. When I try to call pthread_mutex_trylock() on RECURSIVE type of mutex it overwrites adjacent memory location (that is global variable of type structure say x, memory allocated using malloc()). ... (5 Replies)
Discussion started by: liveshell
5 Replies

4. Shell Programming and Scripting

Cannot redirect ouput?????

Hello experts, I'm testing a program that prints error message to the screen. I want to redirect the output to a file using >. but the message only prints on screen and not writing to the file, Any suggestion on what I might try? (3 Replies)
Discussion started by: minifish
3 Replies

5. UNIX for Dummies Questions & Answers

Redirect to variable

how do you redirect stdout into a variable. whenever I try I get an ambiguous redirect error :( I am trying to validate some user input and failing miserably. cal $MONTH $YEAR | grep -c "$DAY" if the above is 1 then it is valid if 0 then not valid. I have been trying to redirect the output... (2 Replies)
Discussion started by: MrAd
2 Replies

6. UNIX for Dummies Questions & Answers

ambiguous redirect

i have following statement in the script echo -e "$str_XML_col_name:$str_field_type;" >> $i_DC_Key_$i_Tgt_DC_key_Schema here $i_DC_Key is DC key and $i_Tgt_DC_key are the variables............... when i ran the script i am getting error rec_merge.sh: $i_DC_Key_$i_Tgt_DC_key_Schema:... (1 Reply)
Discussion started by: mahabunta
1 Replies

7. Programming

Redirect Browser

Hello guys, Is it possible to redirect browser to another socket address? Cheers, Elton (1 Reply)
Discussion started by: EltonSky
1 Replies

8. Shell Programming and Scripting

Redirect question

Hi, I need some help to achive the follwoing task: I have a file named test that contain the following line: 'Hellow world','good morning' I want to attach the content of this file to a variable named var , and then rediarect it to a second file bamed test_new. The result should look like... (2 Replies)
Discussion started by: yoavbe
2 Replies

9. IP Networking

Redirect

I'm sittig behind a firewall that doesn't allow ftp. I have a conection to a UNIX system, connecting throug SSH. Is it possible to redirect the ftp through the UNIX to my computer? (1 Reply)
Discussion started by: <Therapy>
1 Replies

10. Shell Programming and Scripting

Bash overwrites data on screen!!

hi everybody, when i run and compile this: printf("test"); fflush(stdout); nothing appears on screen. if i try this: ___________________________________ printf("test"); fflush(stdout); sleep(10); ___________________________________ then i can see the output "test"... for 10... (4 Replies)
Discussion started by: brain_processin
4 Replies
Login or Register to Ask a Question