Wednesday, January 16, 2013

Some more useful commands

takes the name of the file.
basename
or
cut -f1 -d '.' file.pdb

print the nth column

awk '{print $0}'

remove all dashes 
sed "s/-//g"

remove new lines
awk '{printf "%s", $0}' 

skips first line
sed 1d <File>

Uses the second file as a search.
cat temp.txt | grep -f temp2.txt 

Moves all items in subdirectories to another folder.
find -mindepth 2 -type f -print -exec mv {} ./newDir/ \;

Print everything except the first column
awk '{first = $1; $1 = ""; print $0, first; }' 

Prints out one line after the given search item
grep -A1 key $file

Remove all lines which don't begin with Y....[WC]
sed '/^Y.....[WC]/!d' AnnotatedOrfs.tab > CodingOrfs.tab

Delete All Parentheses
tr -d "\"" 

Take a look only at characters 17-20
cut -c 17-20 

If the 17th position has a B, then delete the line
cat file.txt | sed -r '/^(.{16})B(.*)$/d'

If the 17th position has an A replace it with a space
cat file.txt | sed -r 's/^(.{16})A(.*)$/\1 \2/'