[英]awk increment or change value of a column in a file
I have a bash script that runs a backup job and produce a csv file. 我有一个运行备份作业并生成一个csv文件的bash脚本。
90927597|1356976813998|90927598
How can I increment / change the value of the 3rd column of my CSV file? 如何增加/更改CSV文件第3列的值? ( I actually just want to make it uniq using a random value).
(我实际上只想使用随机值使其成为uniq)。
How can I get that done? 我该怎么做?
Thank you 谢谢
Given the file a
, sed 's/hello/bye/ga' replaces all ocurrencies of
hello with
bye in the file
a`. 鉴于该文件
a
, sed 's/hello/bye/ga' replaces all ocurrencies of
招呼with
轮空in the file
了`。
$ cat a
90927597|1356976813998|90927598
$ sed 's/90927598/hello/g' a
90927597|1356976813998|hello
$
$ sed -i 's/90927598/hello/g' a
$ cat a
90927597|1356976813998|hello
that is, sed -i
replaces the file. 即,
sed -i
替换文件。 Without -i
it shows the replacement on stdout. 不使用
-i
它将在stdout上显示替换项。
each value in the third column with different value for each row, do you think its possible?
第三列中的每个值对每一行都有不同的值,您认为它可能吗? just random, or use the same value + random value, the idea just to make it uniq
只是随机的,或者使用相同的值+随机值,这个想法只是为了使其唯一
$ awk -v v=YOUR_SEED 'BEGIN {FS = "|"; OFS="|" } $3=++v' a > output_file
(idea got from jthill comment ) (想法来自jthill评论 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.