用awk将更改保存在同一文件中的问题 [英] Problem with the save changes in the same file with awk

查看:46
本文介绍了用awk将更改保存在同一文件中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将更改保存在awk中我有类似的文件

I try to save changes in files in awk I have files like

Eq6_1.ndx
eq6_2.ndx
...
...
eq6_10.ndx

这可以正常工作

for index in {1..10}
do
    awk 'f;/hbonds_Other-SOL/{f=1}' eq6_$index.ndx | tee eq7_$index.ndx 
done

但是我想将更改保存在同一文件中,所以我尝试

But I want to save changes in the same file, so I try this

for index in {1..10}
do
    awk 'f;/hbonds_Other-SOL/{f=1}'  "eq6_$index.ndx" > "$tmp" && mv "$tmp" "eq6_$index.ndx"  
done

但是我知道没有这样的文件最后我想尝试一下

But I have information that there is no such file In the end I want to try this

#!/bin/bash
name="eq6"
for index in {1..10}
do
    awk 'f;/hbonds_Other-SOL/{f=1}'  "${name}_$index.ndx" > "$tmp" && mv "$tmp" "{$name}_$index.ndx" 
done

但是我知道没有这样的文件吗?我做错了什么我尝试了此解决方案并且它不起作用

but I have information that there is no such file? What I do wrong I try this solution and it's not working how to write finding output to same file using awk command

推荐答案

tmp 是变量,在尝试使用 $ tmp :

tmp is a variable, you have to actually set it to the name of a file before trying to access that file with $tmp:

tmp=$(mktemp) || exit 1
name='eq6'
for index in {1..10}
do
    awk 'f;/hbonds_Other-SOL/{f=1}'  "${name}_$index.ndx" > "$tmp" && mv "$tmp" "${name}_$index.ndx" 
done

您也有 {$ name} 而不是 $ {name} ,但是我认为那是一个错字.

You also had {$name} instead of ${name} but I assume that was a typo.

这篇关于用awk将更改保存在同一文件中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆