-1

Below is a network log which I want to use as input in my shell command. I need a shell command which should delete all the data except the data columns at the end. My input and output have been provided below. Please help.

INPUT:

SHRNCE4> pmxznh . pmNoTimesIfhoCellFailAddToActSet -m 1 -r
....

Report from 2017-07-24 13:30 UTC to 2017-07-24 14:29 UTC (4 ropfiles)
Node SW: CXP9021776/6_R2XA08

Date: 2017-07-24
Time  Object           pmNoTimesIfhoCellFailAddToActSet
18:00 ManagedElement=1                              191
18:15 ManagedElement=1                              205
18:30 ManagedElement=1                              178
18:45 ManagedElement=1                              215


SHRNCE4> 

OUTPUT:

Time  Object           pmNoTimesIfhoCellFailAddToActSet
18:00 ManagedElement=1                              191
18:15 ManagedElement=1                              205
18:30 ManagedElement=1                              178
18:45 ManagedElement=1                              215
Matthew Verstraete
  • 6,335
  • 22
  • 67
  • 123

4 Answers4

0

You can direct the output of your command with | to sed - utility to edit character stream. Use:

pmxznh . pmNoTimesIfhoCellFailAddToActSet -m 1 -r | sed -e '1,4d'

this should print your desired output on screen

-e '1,4d' tells sed to delete first four lines of input it receives

related: Delete specific line number(s) from a text file using sed? http://www.grymoire.com/Unix/Sed.html

0

Using awk

awk '/Time/{f=1}f && !NF{exit}f'

Your command becomes :

pmxznh . pmNoTimesIfhoCellFailAddToActSet -m 1 -r | awk '/Time/{f=1}f && !NF{exit}f'

Test Results :

Input :

akshay@db-3325:/tmp$ cat testfile
....

Report from 2017-07-24 13:30 UTC to 2017-07-24 14:29 UTC (4 ropfiles)
Node SW: CXP9021776/6_R2XA08

Date: 2017-07-24
Time  Object           pmNoTimesIfhoCellFailAddToActSet
18:00 ManagedElement=1                              191
18:15 ManagedElement=1                              205
18:30 ManagedElement=1                              178
18:45 ManagedElement=1                              215

Output :

akshay@db-3325:/tmp$ awk '/Time/{f=1}f && !NF{exit}f' testfile
Time  Object           pmNoTimesIfhoCellFailAddToActSet
18:00 ManagedElement=1                              191
18:15 ManagedElement=1                              205
18:30 ManagedElement=1                              178
18:45 ManagedElement=1                              215
Akshay Hegde
  • 16,536
  • 2
  • 22
  • 36
0

sed can be used to print all of the lines from a line matching a pattern to the end of the input:

pmxznh . pmNoTimesIfhoCellFailAddToActSet -m 1 -r | sed -n '/^Time/,$p'

If empty lines need to be deleted at the end, the output may be piped to sed '/^$/d' to delete them:

pmxznh . pmNoTimesIfhoCellFailAddToActSet -m 1 -r | sed -n '/^Time/,$p' | sed '/^$/d'

DETAIL

The pattern (regular expression) to be matched for the first line to be printed is ^Time. /^Time/,$ describes a range for the lines to be printed; $ means "to the last line." The p at the end is the command to apply to those lines, and it stands for "print." In other words, print from the first line starting with the string "Time" through the end of the input.

The -n option is to disable sed's default behavior, which is to echo each line of input to the standard output.

If there are other lines starting with "Time" in your input, you may need to modify the regular expression for the first line to be printed.

Luis Guzman
  • 996
  • 5
  • 8
0

If your output will be same as shown sample, then following may help you in same.

Your_command | awk '/^Time/{val=1} val' 
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93