Skip to main content
added 279 characters in body
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

You can do this with sed. The general format is:

sed -n '/pattern1/,/pattern2/d'p' file

Which means "readThe file-n and delete everythingcauses sed not to print unless explicitly told to with p. Som that command will print all lines that fall between a line that matchesmatching pattern1 and the next line that matchesone matching pattern2" (inclusive). If there are multiple matches, multiple lines will be deletedprinted.

In your case, you want to deleteprint everything until the end of the file, so pattern2 will be $. Therefore, you're looking for this:

$ sed -n '/16-02-2020/,$d'$p' file
1016-02-2020
givenThe astop fileprogram name)provides fora linesdynamic containingreal-time aview matchof toa therunning
 given PATTERN system. By default,It grepcan printsdisplay system summary information as well as a list
   of processes or threads currently being managed by the matchingLinux lineskernel.
In addition, two variantThe programstypes egrepof system summary information shown and fgrepthe types, order
   and size of information displayed for processes are available.all egrepuser
 is the sameconfigurable asand grepthat -E.configuration fgrepcan isbe themade samepersistent asacross
 grep -F restarts.

On an unrelated note, fgrep and egrep are deprecated, you should use grep -F and grep -E. See man grep:

In addition, the variant programs egrep and fgrep are the same as grep -E and grep -F, respectively. These variants are deprecated, but are provided for backward compatibility.

You can do this with sed. The general format is:

sed '/pattern1/,/pattern2/d' file

Which means "read file and delete everything between a line that matches pattern1 and the next line that matches pattern2". If there are multiple matches, multiple lines will be deleted.

In your case, you want to delete everything until the end of the file, so pattern2 will be $. Therefore, you're looking for this:

$ sed '/16-02-2020/,$d' file
10-02-2020
given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.
In addition, two variant programs egrep and fgrep are available. egrep is the same as grep -E. fgrep is the same as grep -F

On an unrelated note, fgrep and egrep are deprecated, you should use grep -F and grep -E. See man grep:

In addition, the variant programs egrep and fgrep are the same as grep -E and grep -F, respectively. These variants are deprecated, but are provided for backward compatibility.

You can do this with sed. The general format is:

sed -n '/pattern1/,/pattern2/p' file

The -n causes sed not to print unless explicitly told to with p. Som that command will print all lines that fall between a line matching pattern1 and one matching pattern2 (inclusive). If there are multiple matches, multiple lines will be printed.

In your case, you want to print everything until the end of the file, so pattern2 will be $. Therefore, you're looking for this:

$ sed -n '/16-02-2020/,$p' file
16-02-2020
The top program provides a dynamic real-time view of a running
   system.  It can display system summary information as well as a list
   of processes or threads currently being managed by the Linux kernel.
   The types of system summary information shown and the types, order
   and size of information displayed for processes are all user
   configurable and that configuration can be made persistent across
   restarts.

On an unrelated note, fgrep and egrep are deprecated, you should use grep -F and grep -E. See man grep:

In addition, the variant programs egrep and fgrep are the same as grep -E and grep -F, respectively. These variants are deprecated, but are provided for backward compatibility.

Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

You can do this with sed. The general format is:

sed '/pattern1/,/pattern2/d' file

Which means "read file and delete everything between a line that matches pattern1 and the next line that matches pattern2". If there are multiple matches, multiple lines will be deleted.

In your case, you want to delete everything until the end of the file, so pattern2 will be $. Therefore, you're looking for this:

$ sed '/16-02-2020/,$d' file
10-02-2020
given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.
In addition, two variant programs egrep and fgrep are available. egrep is the same as grep -E. fgrep is the same as grep -F

On an unrelated note, fgrep and egrep are deprecated, you should use grep -F and grep -E. See man grep:

In addition, the variant programs egrep and fgrep are the same as grep -E and grep -F, respectively. These variants are deprecated, but are provided for backward compatibility.