bash - Replace a string in the last 100 records on a file using awk -
So I got around the last 100 records of a file processing, which, using a wc -l Variable declares, but I have a hard one.
The text below is just an example but it really helps me to get the point in the table
1 1986 United States American Eagle Gold 1 1908 Austria-Hungary Franz Josef 100 Corona Silver 10 1981 USA A Pint Gold 1 84 84 Switzerland Gold Gold 1 9 7 9 RSA Cigarrund Gold 0.5 1 9 81 RSA Cigarrund Gold 0.1 1 1986 PRC Panda Silver 1 1986 USA Liberty Dollar Gold 0.25 1986 USA Liberty Call of Calls to this file And assume that there are more than 400 records awk -v v1 = $ (wc -l & lt; coins) piece of 5-dollar 'NR & gt; V1-100 {gsub / gold / magic /; Print} 'coins
This does not actually work for me, if I want to print the fields first, it will work but I have the number of records and then processing them. I want to know how to go about taking the place of the string and if necessary, after closing the processed text, except the processed text, copy the string with the awk and print the whole file which is replaced
Try this one:
awk -v V1 = "$ (wc -l & lt; coins '(v1-100) {gsub (/ gold /," magic "}} 7' coins This 400 lines output (Say that your file has 400 lines), but the replacement was done on the previous 100 lines.
Or get the line number by reading the file twice awk:
< Code> awk 'NR == FNR {num = NR; next} FNR> (num-100) {gsub (/ gold /, "magic"}} 7 coins coins Edit
op only wants 100 lines in output:
awk 'NR == FNR {num = NR; next} FNR> (num-100 } {Gsub (/ gold /, "magic"); print} 'coin coin or The tail : tail -100 Coins | Awk 'gsub (/ gold /, "magic") + 7'
Comments
Post a Comment