Giri
Giri

Reputation: 13

File redirection inside for loop

I have am redirecting the file inside file but at the last the file is going to nullify, my code is like below

#!/bin/ksh
newlycreated=`cat /axphome/gdevarad/file.txt|awk '{print $1}'`

for i in $newlycreated
do

    cat file1.txt |grep -v $i > /axphome/gdevarad/file1.txt

done

file.txt contains

india    30
pakistan 40

file1.txt contains

india    30
pakistan 40
germany  50
japan    60
aus      70

Upvotes: 0

Views: 49

Answers (1)

Walter A
Walter A

Reputation: 19982

Replace > /axphome/gdevarad/file1.txt with >> /axphome/gdevarad/file1.txt so you do not overwrite your results in every loop.
Evn better: Place > /axphome/gdevarad/file1.txt after done .

Upvotes: 1

Related Questions