Paco

Personal Content Organiser

Home / Linux

Navigation

Menu

Search

bash

remove all lines taring with #


sed '/^#/d' $FILE


show everything in file after match


sed '1,/$MATCH/d' $FILE


remove first line in file


tail -n +2 $FILE

Warning


THIS WILL GIVE YOU AN EMPTY FILE!
tail -n +2 "$FILE" > "$FILE"
The reason is that the redirection (>) happens before tail is invoked by the shell.

Use:
tail -n +2 "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE"
The && will make sure that the file doesn't get overwritten when there is a problem.