简体   繁体   English

awk更新记录

[英]awk to update record

I have data in a text file: 我在一个文本文件中有数据:

Customer:HDB:Price:Left:total
Ted 1:rm4:34:197:101

I'm trying to update the latest record for left and total to the database. 我正在尝试更新数据库的剩余总记录。 Why doesn't this expression work? 为什么此表达式不起作用?

awk -F : -v OFS=: -v customer=$customer-v hdb=$hdb \
   -v left=$left -v total=$total \
   '$1==customer && $2==hdb {`$4=left $5=total;`}1' file

1) you forgot ; 1)你忘了; here: 这里:

$4=left; $5=total;

2) space required here: 2)需要的空间:

customer=$customer -v

3) `` not required here: 3)``这里不需要:

{$4=left; $5=total;}

This should work: 这应该工作:

awk -F : -v OFS=: -v customer="$customer" -v hdb="$hdb" -v left="$left" \
  -v total="$total" '$1==customer && $2==hdb { $4=left; $5=total } 1' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM