Netstat

Ever wonder what network activity is happening on your machine? Use netstat.

The most useful command line options:

  • -a = show all network access
  • -b = shows the process, or on windows the process id that is using the network (the process id can be matched up to a process via the task manager)
  • -n = don’t do a dns lookup

You can obviously chain this command together with grep:

  • netstat -anb | grep 80

Fixing Fixed-Width Text Files

To remove the end line characters in a text file that has every line truncated at 80 chars…

perl -pi -e ‘s/(….+)\r\n/$1 /’ filename.txt
perl -pi -e ‘s/\n/\n\n/’ filename.txt

Then open in Write –> copy and paste into word.

Replace Text

Here’s a quick one-liner for perl… replace every occurance of “boring” with “fun”:

perl -pi.bak -e ‘s/boring/fun/’ filename.txt

Recursive Search

I usually use Windows Explorer to find something recursively within a folder hierarchy… but sometimes it doesn’t work based on the file types. When that happens, I fall back to this find + grep combination (available with cygwin utils):

find . -type f -exec grep needle {} \; -print

It looks for the word “needle” in any file under the current directory.

The “-type f” option says, only find files.  The “{}” is replaced with the filename (so you can do “grep -i -XYZ needle {}” if you needed to…