Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I do this:

var=`grep GENRE Billy_Cobham_-_Drum_\&_Voice_2.cue | cut -d ' ' -f 3`
mkdir $var

The file.cue interested line is:

REM GENRE Funky+Jazz

When mkdir creates the directory, the directory showed with ls is:

Funky+Jazz?

I made many tests to understand with many command like awk grep cut sed in all tests reading the terminal the results is "Funky+Jazz". But the string have an hidden "Starting new line". And, it generated the strange result when mkdir command is invoked.

If I open terminal in the Funky+Jazz directory the shell appear as:

 $ @host:~/Desktop/test/5/Funky+Jazz

I don't know how to solve this problem and have a correct directory name without question mark.This is my cue

REM GENRE Funky+Jazz
REM DATE 2006
REM DISCID 920BFB0A
REM COMMENT "ExactAudioCopy v0.95b4"
PERFORMER "Billy Cobham"
TITLE "Drum & Voice 2"
FILE "Billy_Cobham_-_Drum_&_Voice_2.ape" WAVE
  TRACK 01 AUDIO
    TITLE "Waveform"
    PERFORMER "Billy Cobham"
    INDEX 01 00:00:00
  TRACK 02 AUDIO
    TITLE "Real Funk"
    PERFORMER "Billy Cobham"
    INDEX 00 05:04:19
    INDEX 01 05:06:21
  TRACK 03 AUDIO
    TITLE "Running"
    PERFORMER "Billy Cobham"
    INDEX 00 09:42:52
    INDEX 01 09:44:56
  TRACK 04 AUDIO
    TITLE "Final Destination"
    PERFORMER "Billy Cobham"
    INDEX 00 17:30:36
    INDEX 01 17:32:38
  TRACK 05 AUDIO
    TITLE "One More Day To Live"
    PERFORMER "Billy Cobham"
    INDEX 00 24:26:37
    INDEX 01 24:28:38
  TRACK 06 AUDIO
    TITLE "Ozone Part 1"
    PERFORMER "Billy Cobham"
    INDEX 00 29:41:47
    INDEX 01 29:43:39
  TRACK 07 AUDIO
   TITLE "Ozone Part 2"
    PERFORMER "Billy Cobham"
    INDEX 00 31:56:06
    INDEX 01 31:56:16
  TRACK 08 AUDIO
TITLE "Take Seven"
    PERFORMER "Billy Cobham"
    INDEX 00 38:24:64
INDEX 01 38:26:68
  TRACK 09 AUDIO
    TITLE "Let Me Breathe"
PERFORMER "Billy Cobham"
    INDEX 00 44:28:41
    INDEX 01 44:30:41
  TRACK 10 AUDIO
    TITLE "Amazon"
    PERFORMER "Billy Cobham"
    INDEX 00 48:54:16
    INDEX 01 48:56:20
share|improve this question
    
Can you please post an example example_file.cue for testing? –  hakermania Jul 19 '12 at 13:54
1  
sure, i have solved the problems; the cause is ending line character.Probably the cue in my directory was created with no UNIX os.to check if some ending line character is present type: cat -v file.cue if ^M are present i do dos2unix -iso file.cue. All works fine, directory name is correct, in any case i'm like to know any other command can do the sobstitution of this hidden ending lines character. –  johnny cravatta Jul 19 '12 at 20:07
add comment

1 Answer

up vote 1 down vote accepted

A solution is the following:

#!/bin/bash

while read line; do
   if [ "${line:0:10}" = "REM GENRE " ]; then
      folder=$(echo "${line:10}" | tr -d '\n\r')
      mkdir $folder
      break
   fi
done < file.cue
echo "Folder $folder has been created"

Tested with the sample file you have appended as a comment to this answer.

Explanation: At the beginning there is a while loop, which, as you can see from done < file.cue, it reads the file.cue and reads, one by one, the file.cue's lines. The if statement now, the line

if [ "${line:0:10}" = "REM GENRE " ]; then

means: If the first 10 letters of the variable 'line' equals to "REM GENRE " then...

When the if statement is true, we are on the line we are interested in. What we care about this line, is the characters after the 10th letter of $line, though. The ${line:10}, means everything after the 1st 10 letters of variable 'line'.

So, I 'echo' everything after the 1st 10 characters, and, with the help of 'tr' I cut any newline character (which was what caused the problem, in reality). I append this to the variable 'folder' and I create it.

share|improve this answer
    
interesting solution,but sorry the cue i have pasted lost the "ending line character".In fact to test correctly you need the original cue without html reinterprations.tested your script with original dos cue and the results is a folder-name?...yuo can test with orginal cue keep it here: –  johnny cravatta Jul 23 '12 at 10:57
    
dl.dropbox.com/u/8526901/… and if you want to explain the if i will appreciate..thanks in any case. –  johnny cravatta Jul 23 '12 at 11:05
    
Please read my edited answer! –  hakermania Jul 23 '12 at 12:39
    
@hackermania lot of thanks, yes in fact what i'm intersted is the command tr -d'\n\r' tested works fine in any case.Very very useful, and thanks for the explanation of the statement. –  johnny cravatta Jul 24 '12 at 20:40
    
It is hakermania* and now I'm offended! You're welcome :) –  hakermania Jul 25 '12 at 9:11
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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