This question helped me understand how to combine stderr and stdout:
How to redirect stderr to a file
with this command:
gunzip -vc /opt/minecraft/wonders/logs/20* 2>&1
But how may one insert a line break between the two so that the output can appear on separate lines instead of clumped together?
The stderr comes first, which is always 1 line, something like this:
/opt/minecraft/wonders/logs/2017-08-28-2.log.gz:
Whereas the stdout is usually (but not always) multiple lines, like:
06:17:05: Starting minecraft server version 1.10.2
06:18:21: Loading properties
06:18:21: Default game type: SURVIVAL
06:18:21: Generating keypair
06:18:21: Starting Minecraft server on *:25565
06:18:22: Using default channel type
But because there is no newline between them the first line from each file to be unzipped is always something like this:
/opt/minecraft/wonders/logs/2018-08-18-2.log.gz: 06:17:05: Starting minecraft server version 1.10.2
I need these two parts on different lines so I can filter them with grep. But I also want the corresponding stdout directly following its stderr (its filename) so I know which file it comes from. Like this:
/opt/minecraft/wonders/logs/2018-08-18-2.log.gz:
06:17:05: Starting minecraft server version 1.10.2
06:18:21: Loading properties
06:18:21: Default game type: SURVIVAL
06:18:21: Generating keypair
06:18:21: Starting Minecraft server on *:25565
06:18:22: Using default channel type
This is the command I am piping into using with grep:
egrep -iv "^\[.*(stopping|starting|saving|keep|spawn|joined|lost|left|: (<.*>|\/)|\/(help|forge))
Its purpose is to remove certain lines from the log files, leaving the pertinent ones.
grep
? Especially, can you explain the end goal you're trying to achieve ? If you need filtering on both streams, you could probably dogunzip -vc /opt/minecraft/wonders/logs/20* > >(grep 'stdin pattern' ) 2> >(grep 'stderrpattern' )
– Sergiy Kolodyazhnyy Aug 20 '18 at 22:34