Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify a file by using awk?

Tags:

bash

awk

awk '/<ul>/ {ul++} ul == 6 { getline } 1' /var/www/html/INFOSEC/english/test.html

if i run this line of code, the shell will not help me to modify the file, instead, it only output the result in the shell. Can any one help???thx

like image 472
Leo Chan Avatar asked Jul 20 '11 08:07

Leo Chan


1 Answers

The simplest solution is to just send the output to a file; you might want to copy the file beforehand so you don't have to overwrite the file you're reading (which might otherwise lead to undesired behavior).

cp test.html test.html.orig
awk 'your awk script here' test.html.orig >test.html
# and then optionally remove the copy:
rm test.html.orig
like image 115
tdammers Avatar answered Oct 18 '22 02:10

tdammers