• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives
  • Sources
  • Search

Search

Delete lines using awk

November 5, 2021

Here’s how to delete a line from a file using awk.

awk '!/Redhat/' sample.txt > sample.tmp && mv sample.tmp sample.txt

The command above looks for ‘Redhat’ in a file and removes that line from the file.

You can add the line in the crontab to run at reboot if you like.

crontab -e
@reboot awk '!/Redhat/' sample.txt > sample.tmp && mv sample.tmp sample.txt

Filed Under: Linux Tagged With: awk, delete, line

  • Home
  • About
  • Archives
  • Sources
  • Search

Copyright © 2023