![](/img/trans.png)
[英]How to replace using sed command in shell scripting to replace a string from a txt file present in one directory by another?
[英]How to replace a character to another in a column of a text file using awk command in shell scripting
我有一個看起來像的文件
column1 column2 column3
1 45n8 005
2 125n05 007
3 002n012 009
如何使用awk將column2中的'n'替換為'。' 輸出將如下所示:
column1 column2 column3
1 45.8 005
2 125.05 007
3 002.012 009
我對此的嘗試是awk 'BEGIN{OFS=",";}{gsub("n",".",$2);print}' file1.txt>file2.txt
並給了我一個'找不到命令'錯誤
您不想連續替換所有n
,而只替換col2,因此您可以:
awk 'NR>1{sub(/n/,".",$2)}7' file
如果您希望輸出格式看起來更好:
awk 'NR>1{sub(/n/,".",$2)}7' file|column -t
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.