0

I have a script which do some conversions. To be able to save the results in a specific folder i have a file (csv file) the script is reading and from there it takes a string (I do it now with echo/sed/awk)

this is how i am trying to do it:

# creating output directory
PNAME=$( echo -n "$(sed '4q;d' ${FOLDER}/SampleSheet.csv| sed  -e 's/Experiment Name,//')")
echo $PNAME

mkdir /fs/pool/pool-bcfngs/fastq_files/${PNAME}/

The problem is that with this command i always get the \r added to the folder name and I can't automatically creates subfolders.

e.g. the string i am trying to find is this

 sed '4q;d' 171213_NB500982_0018_AHH7CNAFXX/SampleSheet.csv
 Experiment Name,P030

and the results I get is

P030^M

but with the new line inserted. Is there a way to extract the term P030 without adding the P030 to the variable?

  • Have you tried running dos2unix on the file first? – DopeGhoti Jan 19 '18 at 16:10
1

The \r is C notation for the carriage return, which shows up in Windows-style CRLF line endings. It's considered a regular character by the usual text-processing tools on Unixes.

So, from seds point of view, the line in question is something like this (if I got this right):

Experiment Name,P030\r

You could either run the file through tr -d '\r', or dos2unix or sed -e 's/\r$//' to remove the CRs from each line. Or the same for the resulting string. Or deal with it by changing the sed expression that picks up the string you want. This would also work with any other trailing garbage on the line.

e.g. this would remove everything from the line, apart from alphanumerics following the fixed label:

| sed -e 's/.*Experiment Name,\([[:alnum:]]*\).*/\1/'

(\(..\) is used to save ("capture") part of the matching string, and \1 refers the first such a group.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.