File redirection inside for loop

不问归期 提交于 2019-12-25 09:17:15

问题


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

回答1:


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 .



来源:https://stackoverflow.com/questions/41165923/file-redirection-inside-for-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!