Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Wednesday, March 9, 2011

Favorite way to regex a file using perl

Sometimes you want to do some magic fu on your file, while it's not loaded in a vim buffer. This is what I use with perl. I know there is probably a way to do this with sed, but I couldn't find it quickly enough. Most of the time when I do a search and replace out side of vim I want to replace something that's already in the file, with itself in a different position. For example:

I want to replace variablewordspace with variablewordtime, so in the file var.txt I have:

variablewordspace
hammerspace

So what I would do is:


cat var.txt | perl -pe 's/(\w+)space/\1time/'

which would give me the output:


variablewordtime
hammertime



For a brief description:
You are display the file var.txt, through the cat command. Then using the pipe (|) you are passing that to perl, with the switches p and e. Switch e allows you to run from the command line without explicitly writing a perl program, while switch p allows you to run a program against every line on standard input, and prints whatever is in $_ after each line. A search and replace using s/// with the search term in the first set of slashes

/(\w+)space/

The parentheses mark that as a group.

The \w+ means any number of word characters, as where the 'space' just represents the word space.

In the last set of slashes is what you want to replace it with.

/\1time/

\1 represents what is in that first set of parenthesis.

And time of course, represents the letters 'time'

Tuesday, February 12, 2008

True Crypt for n00bs.

http://www.truecrypt.org/
The truecrypt install is straight foreword and similar to the install of most other applications. The first install screen will ask whether to install or extract, and the default which is install is fine. Again on the next page most likely the defaults are fine and then click install. It will ask if you want to see the release notes, click no. Then click finish. Now to open truecrypt. Double click on the true crypt icon on your desktop.


Click create volume. Now for this tutorial we will choose to create a file container then click next and then click create a standard true crypt volume.

Choose where to save your encrypted file volume. The default of AES and RIPEMD-160 are sufficient. You will need to remember what encryption scheme you used so either make a mental note or write it down. I like to make my truecrypt file 600 megs, so if I need to archive it or send it somewhere to be archived(like a lawyer), then it will fit on a cd.

Your password is important and you must remember it, it needs to be a strong password. Strong passwords are denoted by five characteristics. They need to have Upper Case and Lower Case letters and Symbols and numbers. Length is the other factor. Ie@Tpietw1ce@d4Y, is a strong password. You can use a key file if you want but it will complicate things if you want to use your encrypted file on another computer or if that keyfile is corrupted. As far as volume format the defaults are fine. Now to mount your file as a volume go to the main truecrypt screen.


Choose a drive letter like H: . Hit the select file button. Choose your file. Hit the mount button. You will be prompted for your password. Your file will be mounted as the h: drive and anything you put in it will be encrypted. Remember to dismount the drive with the dismount all button whenever you are not using it.