...
Code Block | ||
---|---|---|
| ||
rm -rf ~/test; mkdir ~/test; cd ~/test find /stor/work/CCBB_Workshops_1/bash_scripting/fastq -name "*.gz" | xargs ln -sf -t . |
Removing file suffixes and prefixes
Sometimes you want to take a file path like ~/my_file.something.txt and extract some or all of the parts before the suffix, for example, to end up with the text my_file here. To do this, first strip off any directories using the basename function. Then use the odd-looking syntax ${<variable-name>%%.<suffix-to-remove>}
or ${<variable-name>##<prefix-to-remove>}
.
Code Block | ||
---|---|---|
| ||
path=~/my_file.something.txt; echo $path filename=`basename $path`; echo $filename # isolate the filename prefix by stripping the ".something.txt" suffix prefix=${filename%%.something.txt} echo $prefix # isolate the filename suffix by stripping the "my_file.something." prefix suffix=${filename##my_file.something.} echo $suffix |
Tricks with sort & uniq
The ~/test/joblist.txt file you just symlink'd describes sequencing job/run pairs, tab-separated. We can use sort and uniq to collapse and count entries in the run name field (column 2):
...