Julie's command line cheatsheet - meyermicrobiolab/Meyer_Lab_Resources GitHub Wiki

Misc. command line tricks

Basics in navigating directories

. current directory

.. parent directory

~ home directory

cd ..

merge files, can be any number of input files

cat file1 file2 > newfile

cat *_R1.fastq.gz > Halo_R1.fastq.gz

split files based on number of lines (use multiples of 4 for .fastq files) or by size

split -l [# of lines] file split -b [# of bytes] file

count sequences in a fasta file (does not work on fastq files)

grep -c "^>" file.fa

count sequences in a fastq file

grep -c "^+" file.fastq

Remove windows carriage returns on the command line

sed 's/^M/\n/g' file_in > file_out

[You MUST type this in, not cut and paste. To get ^M, hold down CTRL then hit V then M]

Rename a directory of fastq.gz files

I wanted to add a suffix (here "-A") to my amplicon files after cutadapt. Use command line to navigate to the directory containing files to be edited then copy and paste in the following for forward reads:

for f in *R1_cut.fastq.gz; do mv -- "$f" "${f%_*_L001_R1_cut.fastq.gz}-A_R1_cut.fastq.gz" done

Now for the reverse reads:

for f in *R2_cut.fastq.gz; do mv -- "$f" "${f%_*_L001_R2_cut.fastq.gz}-A_R2_cut.fastq.gz" done

⚠️ **GitHub.com Fallback** ⚠️