Editing without an editor
Written by vaheeD on January 4, 2013
Editing without an editor
- Difficulty: Intermediate
- Application: Various
Very long files are often hard to manipulate with a text editor. If you need to do it regularly, chances are you’ll find it much faster to use some handy command-line tools instead, like in the following examples.
To print columns eg 1 and 3 from a file file1 into file2, we can use awk:
awk '{print $1, $3}' file1 > file2
To output only characters from column 8 to column 15 of file1, we can use cut:
cut -c 8-15 file1 > file2
To replace the word word1 with the word word2 in the file file1, we can use the sed command:
sed "s/word1/word2/g" file1 > file2
This is often a quicker way to get results than even opening a text editor.