| 1 |
Process by Contents |
| 2 |
|
| 3 |
sort Sorts lines of text |
| 4 |
|
| 5 |
-f Ignore case |
| 6 |
-n Numeric comparison |
| 7 |
-r Reverse result order |
| 8 |
-R Random order |
| 9 |
|
| 10 |
-k Field key (start,stop or first) |
| 11 |
-u Unique lines with identical keys |
| 12 |
|
| 13 |
-b Ignore leading blanks |
| 14 |
-s Stable sort |
| 15 |
-t Specify field separator |
| 16 |
|
| 17 |
uniq Removes repeated lines |
| 18 |
|
| 19 |
-c Count occurrences |
| 20 |
-i Ignore case |
| 21 |
|
| 22 |
-f Ignore first n fields |
| 23 |
-s Ignore first n characters |
| 24 |
|
| 25 |
-d Only output repeated lines |
| 26 |
-u Only output non-repeated lines |
| 27 |
|
| 28 |
grep Matches patterns using regular expressions |
| 29 |
|
| 30 |
-i Ignore case |
| 31 |
-v Invert search |
| 32 |
-w Search expression as a word |
| 33 |
-x Search expression as whole line |
| 34 |
|
| 35 |
-e Specify individual pattern |
| 36 |
|
| 37 |
-c Only count number of matches |
| 38 |
-n Print line numbers |
| 39 |
-A Number of lines after match |
| 40 |
-B Number of lines before match |
| 41 |
|
| 42 |
Regular Expressions |
| 43 |
|
| 44 |
Characters |
| 45 |
|
| 46 |
. Any single character (except newline) |
| 47 |
\w Alphabetic [A-Za-z], numeric [0-9], or underscore (_) |
| 48 |
\s Whitespace (space or tab) |
| 49 |
\ Escapes special characters |
| 50 |
[] Matches any enclosed characters |
| 51 |
|
| 52 |
Positions |
| 53 |
|
| 54 |
^ Beginning of line |
| 55 |
$ End of line |
| 56 |
\b Word boundary |
| 57 |
|
| 58 |
Repeat Matches |
| 59 |
|
| 60 |
? 0 or 1 |
| 61 |
* 0 or more |
| 62 |
+ 1 or more |
| 63 |
{n} Exactly n |
| 64 |
|
| 65 |
Escape Sequences |
| 66 |
|
| 67 |
\n Line break |
| 68 |
\t Tab character |
| 69 |
|
| 70 |
Modify Contents |
| 71 |
|
| 72 |
sed Replaces text strings |
| 73 |
|
| 74 |
-e Specify individual expression |
| 75 |
s/// Substitute |
| 76 |
/g Global |
| 77 |
/I Case-insensitive |
| 78 |
/p Print |
| 79 |
|
| 80 |
tr Translates characters |
| 81 |
|
| 82 |
-d Delete character |
| 83 |
-s Squeeze runs of characters |
| 84 |
|
| 85 |
rev Reverses characters on line |
| 86 |
|
| 87 |
Format Contents |
| 88 |
|
| 89 |
column Aligns columns by content width |
| 90 |
|
| 91 |
-s Specify field separator |
| 92 |
-t Create table |
| 93 |
|
| 94 |
expand Aligns columns to specified positions |
| 95 |
|
| 96 |
-t Tab positions |
| 97 |
|
| 98 |
fold Wraps lines at a specific width |
| 99 |
|
| 100 |
-w Line width |
| 101 |
-s Fold at spaces |
| 102 |
|
| 103 |
Filter by Position |
| 104 |
|
| 105 |
cut Removes parts of lines |
| 106 |
|
| 107 |
-c Characters to keep |
| 108 |
-f Fields to keep |
| 109 |
-d Specify field separator |
| 110 |
-s Suppress lines with no delimiters |
| 111 |
|
| 112 |
head Prints first lines |
| 113 |
|
| 114 |
-n Number of lines |
| 115 |
-n -2 skips last two lines |
| 116 |
|
| 117 |
tail Prints last lines |
| 118 |
|
| 119 |
-n Number of lines |
| 120 |
-n +3 skips first two lines |
| 121 |
-r Reverse lines |
| 122 |
|
| 123 |
Miscellaneous |
| 124 |
|
| 125 |
wc Counts words, lines, or characters |
| 126 |
|
| 127 |
-c Characters |
| 128 |
-l Lines |
| 129 |
-w Words |
| 130 |
|
| 131 |
xargs Constructs arguments |
| 132 |
|
| 133 |
-n Number of words per batch |
| 134 |
|
| 135 |
mktemp Make temporary file |
| 136 |
|
| 137 |
join Join columns in files by common field |
| 138 |
|
| 139 |
paste Merge columns in files by line number |
| 140 |
|
| 141 |
File Compression |
| 142 |
|
| 143 |
tar Archive files |
| 144 |
|
| 145 |
-c Create archive |
| 146 |
-f Name of output file |
| 147 |
-z Compress archive with gzip |
| 148 |
|
| 149 |
gzip Compress file |
| 150 |
|
| 151 |
-k Keep original file |
| 152 |
-9 Best compression |
| 153 |
|
| 154 |
unzip Decompress .zip archive |
| 155 |
|
| 156 |
-p Pipe to stdout |
| 157 |
|
| 158 |
gzcat Decompress .gz archive and pipe to stdout |
| 159 |
|
| 160 |
Directory and File Navigation |
| 161 |
|
| 162 |
cd Changes directory |
| 163 |
|
| 164 |
/ Root |
| 165 |
~ Home |
| 166 |
. Current |
| 167 |
.. Parent |
| 168 |
- Previous |
| 169 |
|
| 170 |
ls Lists file names |
| 171 |
|
| 172 |
-1 One entry per line |
| 173 |
-a Show files beginning with dot (.) |
| 174 |
-l List in long format |
| 175 |
-R Recursively explore subdirectories |
| 176 |
-S Sort files by size |
| 177 |
-t Sort by most recently modified |
| 178 |
.* Current and parent directory |
| 179 |
|
| 180 |
pwd Prints working directory path |
| 181 |
|
| 182 |
File Redirection |
| 183 |
|
| 184 |
< Read stdin from file |
| 185 |
> Redirect stdout to file |
| 186 |
>> Append to file |
| 187 |
2> Redirect stderr |
| 188 |
2>&1 Merge stderr into stdout |
| 189 |
| Pipe between programs |
| 190 |
<(cmd) Execute command, read results as file |
| 191 |
|
| 192 |
Shell Script Variables |
| 193 |
|
| 194 |
$0 Name of script |
| 195 |
$n Nth argument |
| 196 |
$# Number of arguments |
| 197 |
"$*" Argument list as one argument |
| 198 |
"$@" Argument list as separate arguments |
| 199 |
$? Exit status of previous command |
| 200 |
|
| 201 |
Shell Script Tests |
| 202 |
|
| 203 |
-d Directory exists |
| 204 |
-f File exists |
| 205 |
-s File is not empty |
| 206 |
-n Length of string is non-zero |
| 207 |
-x File is executable |
| 208 |
-z Variable is empty or not set |
| 209 |
|
| 210 |
Shell Script Options |
| 211 |
|
| 212 |
set Set optional behaviors |
| 213 |
|
| 214 |
-e Exit immediately upon error |
| 215 |
-u Treat unset variables as error |
| 216 |
-x Trace commands and arguments |
| 217 |
|
| 218 |
File and Directory Extraction |
| 219 |
|
| 220 |
BAS=$(printf pubmed%03d $n) |
| 221 |
DIR=$(dirname "$0") |
| 222 |
FIL=$(basename "$0") |
| 223 |
|
| 224 |
Remove Prefix |
| 225 |
|
| 226 |
FILE="example.tar.gz" |
| 227 |
# ${FILE#.*} -> tar.gz |
| 228 |
## ${FILE##.*} -> gz |
| 229 |
|
| 230 |
Remove Suffix |
| 231 |
|
| 232 |
FILE="example.tar.gz" |
| 233 |
TYPE="http://identifiers.org/uniprot_enzymes/" |
| 234 |
% ${FILE%.*} -> example.tar |
| 235 |
${TYPE%/} -> http://identifiers.org/uniprot_enzymes |
| 236 |
%% ${FILE%%.*} -> example |
| 237 |
|
| 238 |
Loop Constructs |
| 239 |
|
| 240 |
while IFS=$'\t' read ... |
| 241 |
for sym in HBB BRCA2 CFTR RAG1 |
| 242 |
for col in "$@" |
| 243 |
for yr in {1960..2020} |
| 244 |
for i in $(seq $first $incr $last) |
| 245 |
for fl in *.xml.gz |