...
Expand |
---|
|
Code Block |
---|
| tail -n +2 ~/data/sampleinfo.txt | \
while IFS= read line; do
jobName=$( echo "$line" | cut -f 1 )
sampleName=$( echo "$line" | cut -f 3 )
if [[ "$jobName" == "" ]]; then continue; fi
echo "Project_${jobName}/${sampleName}.fastq.gz"
done | tee pathnames.txt |
|
A few odds and ends
Arithemetic in bash
Arithmetic in bash is very weird:
Code Block |
---|
|
echo $(( 50 * 2 + 1 ))
n=0
n=$(( $n + 5 ))
echo $n |
And it only returns integer values, after truncation.
Code Block |
---|
|
echo $(( 4 / 2 ))
echo $(( 5 / 2 ))
echo $(( 24 / 5 )) |
As a result, if I need to do anything other than the simplest arithemetic, I use awk:
Code Block |
---|
|
awk 'BEGIN{print 4/2}'
echo 3 2 | awk '{print ($1+$2)/2}' |
You can also use the printf function in awk to control formatting. Just remember that a linefeed ( \n ) has to included in the format string:
Code Block |
---|
|
echo 3.1415926 | awk '{ printf("%.2f\n", $1) }' |
You can even use it to convert a decimal number to hexadecimal using the %x printf format specifier. Note that the convention is to denote hexadecimal numbers with an initial 0x.
Code Block |
---|
|
echo 65 | awk '{ printf("0x%x\n", $1) }' |
Removing file suffixes and prefixes
...