Chapter 9 Tips

  • line ending differece: Windows: ‘’ Mac: ‘’

Linux: ‘’

converting:

Windows->Linux : sed -i 's/\r$//' file.txt
Linux->Windows : sed -i 's/$/\r/' file.txt
Mac->Linux : cat old.txt | tr "\r" "\n" > new.txt
Linux->Mac : cat old.txt | tr "\n" "\r" > new.txt

awk add $3

awk -F '\t' '{sum += $3} END {print sum}' herpes

delete empty lines

sed '/^\s*$/d' method2_G

add first line (table head) to a file

sed -i '1s/^/key\tlocus_tag\tproduct\n/' G_geneonly_pro 

add 3 empty TAB to the beginningof the last line of a file

tac Avian_count_genome.txt_avg | sed '1s/^/\t\t/'  | tac >aaa
  • delete all the files in current directory (and below) that are size zero.
find  .  -size  0 -print0 |xargs -0 rm 
  • delete all empty directories in current dir
find . -empty -type d -delete
  • list all directories in Unix
ls -d */ -1 | sed 's/\///g'
  • only keep the .logfile
rm !(*.logfile)
  • list all the subdir name in current dir and start from the 3rd line
ls -1d */ |sed  's/\///g'| tail  -n+3  > samplename_list
  • print line 3076
sed -n '3076p; 3077q' file