Data Manipulation

Data wrangling

# If file is not specified, the file /usr/share/dict/words is used.
look phy|head -n 10
# Phil
# Philadelphia
# Philadelphia's
# Philby
# Philby's
# Philip
# Philippe
# Philippe's
# Philippians
# Philippine

Repeat printing string n times (e.g. print 'hello world' five times)

printf 'hello world\n%.0s' {1..5}

Do not echo the trailing newline

Copy a file to multiple files (e.g copy fileA to file(B-D))

Delete all non-printing characters

Remove newline / nextline

Replace newline

To uppercase/lowercase

Translate a range of characters (e.g. substitute a-z into a)

Compare two files (e.g. fileA, fileB)

Compare two files, strip trailing carriage return/ nextline (e.g. fileA, fileB)

Number a file (e.g. fileA)

Join two files field by field with tab (default join by the first column of both file, and default separator is space)

Combine/ paste two or more files into columns (e.g. fileA, fileB, fileC)

Group/combine rows into one row

Fastq to fasta (fastq and fasta are common file formats for bioinformatics sequence data)

Reverse string

Generate sequence 1-10

Find average of input list/file of integers

Generate all combination (e.g. 1,2)

Generate all combination (e.g. A,T,C,G)

Read file content to variable

Echo size of variable

Echo a tab

Split file into smaller file

Create a large amount of dummy files (e.g 100000 files, 10 bytes each):

Rename all files (e.g. remove ABC from all .gz files)

Remove file extension (e.g remove .gz from filename.gz)

Add file extension to all file(e.g add .txt)

Squeeze repeat patterns (e.g. /t/t --> /t)

Do not print nextline with echo

View first 50 characters of file

Cut and get last column of a file

Add one to variable/increment/ i++ a numeric variable (e.g. $var)

Cut the last column

Cat to a file

Clear the contents of a file (e.g. filename)

Append to file (e.g. hihi)

Working with json data

Decimal to Binary (e.g get binary of 5)

Wrap each input line to fit in specified width (e.g 4 integers per line)

Sort a file by column and keep the original order

Right align a column (right align the 2nd column)

To both view and store the output

Show non-printing (Ctrl) characters with cat

Convert tab to space

Convert space to tab

Display file in octal ( you can also use od to display hexadecimal, decimal, etc)

Reverse cat a file

Reverse the result from uniq -c

Last updated

Was this helpful?