LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-23-2021, 04:03 PM   #16
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,579

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097

What shell is executing this? What does "type echo" show? It looks like your echo command is treating "," as an operator.

Just a suggestion unrelated to yuor problem: You don't need to test for a nonexistent or zero-length "$db" file. The ">>" redirection will create the file if it does not currently exist.

Last edited by rknichols; 10-23-2021 at 04:04 PM.
 
Old 10-23-2021, 04:24 PM   #17
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 324

Original Poster
Rep: Reputation: Disabled
Thanks for the simple code shruggy , but i have the same problem as before , that did not solve the variables that i need to write in data.csv .
We returned to point 0 again .
By default in every thread i make here someone always simplify the code ))

Anyway check the image .
Attached Thumbnails
Click image for larger version

Name:	Image9.jpg
Views:	12
Size:	190.8 KB
ID:	37555  
 
Old 10-23-2021, 04:47 PM   #18
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
As I said, you may try cueprint.

Using a cue sheet file from Wikipedia:
Code:
$ drd=/media/Disk5/Flac/xxx;cueprint -t"%p - %t , $drd\n" wp.cue
Faithless - Reverence , /media/Disk5/Flac/xxx
Faithless - She's My Baby , /media/Disk5/Flac/xxx
Faithless - Take the Long Way Home , /media/Disk5/Flac/xxx
Faithless - Insomnia , /media/Disk5/Flac/xxx
Faithless - Bring the Family Back , /media/Disk5/Flac/xxx
Faithless - Salva Mea , /media/Disk5/Flac/xxx
Faithless - Dirty Old Man , /media/Disk5/Flac/xxx
Faithless - God Is a DJ , /media/Disk5/Flac/xxx
Of course, this would work only as long as you don't have any % in $drd. Just extracting performer and title with cueprint would be safer.

Like this, using a cue sheet file from HAK:
Code:
$ cueprint -t'%p - %t\n' hak.cue
The Specials - Gangsters
The Specials - Rudi, A Message To You
The Specials - Nite Klub
The Specials - Too Much Too Young
The Specials - Guns Of Navarone
The Specials - Rat Race
The Specials - Stereotype
The Specials - International Jet Set
The Specials - Do Nothing
The Specials - Ghost Town
The Specials - Why?
The Specials - Friday Night, Saturday Morning
The Specials - War Crimes
The Specials - Racist Friend
The Specials - Nelson Mandela
The Specials - (What I Like Most About You Is Your) Girlfriend
Or you may double each % in $drd for cueprint
Code:
$ drd="/media/Disk5/Flac/From 0% to 100%"; echo ${drd//%/%%}
/media/Disk5/Flac/From 0%% to 100%%
$ cueprint -t"%p - %t , ${drd//%/%%}\n" wp.cue
Faithless - Reverence , /media/Disk5/Flac/From 0% to 100%
Faithless - She's My Baby , /media/Disk5/Flac/From 0% to 100%
Faithless - Take the Long Way Home , /media/Disk5/Flac/From 0% to 100%
Faithless - Insomnia , /media/Disk5/Flac/From 0% to 100%
Faithless - Bring the Family Back , /media/Disk5/Flac/From 0% to 100%
Faithless - Salva Mea , /media/Disk5/Flac/From 0% to 100%
Faithless - Dirty Old Man , /media/Disk5/Flac/From 0% to 100%
Faithless - God Is a DJ , /media/Disk5/Flac/From 0% to 100%

A thought. Could a performer name start with a dash? Then better use printf rather than echo.
Code:
printf %s\\n "$performer - ${titles[$i]} , $drd" >>"$db"

Last edited by shruggy; 10-23-2021 at 05:34 PM.
 
Old 10-23-2021, 05:29 PM   #19
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 324

Original Poster
Rep: Reputation: Disabled
Quote:
rknichols wrote:
What shell is executing this? What does "type echo" show? It looks like your echo command is treating "," as an operator.
"echo is a shell builtin"

Most likely , is there a way to bypass it ?
printf is not helping also .

I have tried * & | as replacements in echo and still got the same output

Last edited by pedropt; 10-23-2021 at 05:37 PM.
 
Old 10-23-2021, 05:34 PM   #20
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
Quote:
Originally Posted by pedropt View Post
Most likely , is there a way to bypass it ?
Sure. /bin/echo

But I don't think echo is the culprit. Rather the way you generate art and song looks fragile and problematic:
Code:
grep "PERFORMER" "$scue" | sed 's/PERFORMER//' | sed 's/"//g' | sed 's/^ *//g' | sed '/^[[:space:]]*$/d' | uniq > "$art"
grep "TITLE" "$scue" | sed 's/TITLE//' | sed 's/"//g' | sed 's/^ *//g' | sed '/^[[:space:]]*$/d' | sed -e '1d' > "$song"
Even if you simplify it like this
Code:
sed '/PERFORMER/!d;s///;s/"//g;s/^ *//;/^$/d' "$scue"|uniq >"$art"
sed '/TITLE/!d;s///;s/"//g;s/^ *//;/^$/d' "$scue" >"$song"
But I don't know the cue sheet file format enough to judge. Again, rather than doing ad-hoc parsing with sed, I'd use a specialized tool (cueprint).

Last edited by shruggy; 10-23-2021 at 06:01 PM.
 
1 members found this post helpful.
Old 10-23-2021, 06:58 PM   #21
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 324

Original Poster
Rep: Reputation: Disabled
New Update

Using cat on data.csv shows me this :
Quote:
root@Cloud:/usr/local/share/dbserver# cat data.csv
/media/Disk5/Flac/Albums & Remixed/Alan Barry - Greatest Hits & Remixes (2019)/CD1
/media/Disk5/Flac/Albums & Remixed/Alan Barry - Greatest Hits & Remixes (2019)/CD1
but using an editor like nano i get this :
Quote:
Alan Barry
- Good Vibrations (Radio Version)
/media/Disk5/Flac/Albums & Remixed/Alan Barry - Greatest Hits & Remixes (2019)/CD1
Alan Barry
- Come On (Radio Version)
/media/Disk5/Flac/Albums & Remixed/Alan Barry - Greatest Hits & Remixes (2019)/CD1
I have no idea why cat dont show everything , i only notice it now when i used nano .

Also they are not on same line , they are in separated lines each variable !!!!

For last and more strange i get in nano "read 271 lines (Converted from Mac format)" !!!
i am not in mac , i am in linux and data.csv was created in linux .

Quote:
root@Cloud:/usr/local/share/dbserver# file data.csv
data.csv: CSV text
image11 attached shows file opened on leafpad editor
Any idea ?
Attached Thumbnails
Click image for larger version

Name:	Image11.jpg
Views:	3
Size:	117.8 KB
ID:	37557  

Last edited by pedropt; 10-23-2021 at 07:08 PM.
 
Old 10-23-2021, 07:04 PM   #22
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
That means there are embedded CR characters (\r, ^M, ASCII 13). cat -A will show them.

An explanation that I have. Your .cue files are in DOS format (CRLF). Again, cat -A will show it. Command substitution $() and mapfile -t will remove trailing LF (\n, ^J, ASCII 10), but CR will be left intact. When you cat it, the lines get overlapped, i.e. performer gets overwritten by title which in turn gets overwritten by $drd (remember how carriage return on a typewriter works).

sed 's/\s*$//' to the rescue.

Again, I'm pretty sure that cueprint can cope with this.

Last edited by shruggy; 10-23-2021 at 07:35 PM.
 
Old 10-23-2021, 07:20 PM   #23
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 324

Original Poster
Rep: Reputation: Disabled
Quote:
That means there are embedded CR characters (\r, ^M). cat -A will show them.
Exactly .
Is there a way to avoid this in the code ?
 
Old 10-23-2021, 07:25 PM   #24
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,037

Rep: Reputation: Disabled
Trim trailing white space when you generate $art and $song:
Code:
sed '/PERFORMER/!d;s///;s/"//g;s/^ *//;s/\s*$//;/^$/d' "$scue"|uniq >"$art"
sed '/TITLE/!d;s///;s/"//g;s/^ *//;s/\s*$//;/^$/d' "$scue" >"$song"
Or better, use cueprint instead.

Last edited by shruggy; 10-23-2021 at 07:32 PM.
 
1 members found this post helpful.
Old 10-23-2021, 07:36 PM   #25
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 324

Original Poster
Rep: Reputation: Disabled
Bingo , you hit it .
Thank you so much for all your time and patience on this one , really appreciated .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Unable to use variable (i) from loop with FOR in a another variable pedropt Programming 5 12-25-2017 12:31 PM
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 10:57 AM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 01:08 AM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 06:17 PM
while loop or for loop? mijohnst Programming 18 11-21-2005 05:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration