-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOne-Liners - General
57 lines (38 loc) · 1.44 KB
/
One-Liners - General
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#Count lines in multiple files and display lines per file
grep -c filenames
#Mutation spectrum (base pair change) of SNVs in a BED file
cut -f4,5 filename | sort | uniq -c
#Find difference between 2 files
awk 'FNR==NR{f[$1];next}(!($1 in f)) ' file1 file2
#Find pattern and display n lines above pattern (n=10)
grep "pattern" filename -B 10
#Find pattern and display n lines below pattern (n=10)
grep "pattern" filename -A 10
#Combine files
cat file1 file2 file3 > newfile
#Replace ^M with line break in VI text editor
%s/^M/\r/g
#Replace space in the beginning of line VI text editor
%s/^ \+//
#Compare file1 and file2; suppress lines unique to FILE1
comm -1 file1 file2 > file3
#Compare file1 and file2, suppress lines unique to FILE2
comm -2 file1 file2 > file3
#Compare file1 and file2, suppress lines that appear in both files
comm -3 file1 file2 > file3
#Extract last field per line
awk '{ print $NF }' filename
#Mutation spectrum (base Pair change) of SNVs in a BED file
cut -f4,5 filename | sort | uniq -c
#Extract the Nth string in a line
cut -c Nth
#Unzip multiple tar files
for file in *.tar.gz; do tar -zxf $file; done
#Extract the 8th line of single file
sed '8q;d' filename
#Extract the 8th line of multiple files
awk 'FNR == 8' *filenames
#Find 2 patterns in the same file
cat filename | grep -e "pattern1" -e "pattern2"
#Append output to beginning of file
cat <(command) filename >tmp && mv tmp filename