Sed

Sed is a search-and-replace function for text files used from the command line. It will most likely be easier to just search and replace in a visual text editor, however certain functions like making Mac files Linux-friendly may require the use of sed.

Relevant Usage at Saierlab
The only time so far sed has been required has been making a mac file compatible with a linux machine.

How to Know When to Convert from Mac to Linux
If you're not on a Linux machine, this is not your problem. Newer Macs should not cause this problem either.

Navigate to the file, and read it's contents with the command "cat ". If it shows "^M" where it should show newlines, then you have a problem with the linux machine reading a mac file.

For example: You expect the file to look like this: This is line 1. This is line 2. This is line 3. But instead it looks like this: This is line 1.^MThis is line 2.^MThis is line 3.

Converting the File
MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED
 * MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED
 * MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED
 * MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED

This is the terminal command: sed -i 's/^M/\n/g' filename

Note that ^M is not typed as "caret M" but as ctrl+v ctrl+m. So to type the above command, ENTER THIS EXACT SEQUENCE OF KEYS:


 * s
 * e
 * d
 * i
 * s
 * 
 * 
 * n
 * g
 * 
 * 
 * 
 * n
 * g
 * 
 * g
 * 
 * 
 * 
 * 

If you're not absolutely sure, then please ask before you corrupt a file.

How To Know When to Remove Tabs with Sed
You shouldn't.

But I'm Gangsta So I Don't Follow Instructions
This section is for removing tabs from a text file when you're using a mac, not for transferring between mac and linux. This has not been tested on a linux machine.

Navigate to the file, and read it's contents with the command "cat ". It should output the contents of the file. Cool. Then you use the command "cat | grep \t". If no lines are returned, then there are already no tabs in the file, and you're already done. If something is output, then use a text editor with search-and-replace functionality to take out tabs. Oh, you want to gamble with your life? Keep reading then.

Converting the File
MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED
 * MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED
 * MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED
 * MAKE A COPY OF THE FILE YOU WILL RUN SED ON BEFORE RUNNING SED

The command is : sed -i 's/    //g'

 is whatever you to replace with. If you don't know, just don't put anything for it, and the command will be: sed -i 's/    //g'

Note that "    " is not typed as but as . So to type the above command, ENTER THIS EXACT SEQUENCE OF KEYS:


 * s
 * e
 * d
 * i
 * s
 * 
 * 
 * g
 * 
 * <ctrl+v>
 * <WHATEVER>
 * g
 * <the name of the file you want to edit>
 * <WHATEVER>
 * g
 * <the name of the file you want to edit>
 * <the name of the file you want to edit>
 * <the name of the file you want to edit>
 * <the name of the file you want to edit>

If you're not absolutely sure, then please ask before you corrupt a file.

Person to Ask

 * Bryant