Tag: Linux

Linux – How to cut a log file based on timestamp

You can use the command ‘sed’ to specify an interval to cut a log file. ‘sed’ performs editing operations on information coming from standard input or a file. It edits line-by-line and in a non-interactive way.

Example to cut a log file based on timestamp:

sed '1,/2017\/01\/11 09\:00/ d;/2017\/01\/11 10\:00/,$ d' <logfile>

This command will just show lines between ‘2017/01/11 09:00’ and ‘2017/01/11 10:00’.
In reality, the command is removing all lines before ‘2017/01/11 09:00’ and after ‘2017/01/11 10:00’ (including lines with ‘2017/01/11 10:00’).

You need to modify the command to match your log file and your needs.


Running a Linux application using Cygwin/X

Sometimes I need to run a X11 application from Microsoft Windows and the way I normally do that is by using Cygwin/X.

Installing Cygwin/X

Run Cygwin setup and select the ‘xinit’ package from the ‘X11’ category. You can find the setup file in Cygwin page. You will need SSH as well if you don’t have it installed yet. Cygwin also provides a package for SSH.

Running the application

After installing Cygwin/X, follow the following steps:

  1. Start “XWin Server”
  2. Start XTerm by going to “X applications menu/System Tools/XTerm” for your Cygwin/X Server in the system tray.
  3. XTerm will open (white screen). Now, you should connect to the Linux server you want to use via SSH using -XY to establish your secure shell connection with X11 support:
    It is easier to establish proper X11 forwarding using the XTerm window because it sets a DISPLAY variable for you automatically, which is needed by the X Window System.echo $DISPLAYIf you would like to establish the connection from your main Cygwin shell instead, you will have to set your DISPLAY manually.  Either of these commands will do that.export DISPLAY=:0
    export DISPLAY=:0:0
  4. Open the application you want to run. You might want to run “xlogo” to test the connection first and following screen will be displayed: