weird echo output?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting weird echo output?
# 1  
Old 03-23-2008
Computer weird echo output?

Code:
#!/bin/bash

INPUT=$1
if [ "$INPUT" -lt "10" ]
then
        INPUT=0$1
        TRACKNUMBER=$INPUT
fi
TRACKNUMBER=$INPUT
echo "Track Number:" $TRACKNUMBER


if [ ! -e "split-track${TRACKNUMBER}.wav" ]
then
        echo "File Does Not Exist!: split-track"${TRACKNUMBER}".wav"
        exit 0
fi

CUEFILE="$2"

CDTITLE=`less "$CUEFILE"|grep -B10 FILE|grep TITLE|sed 's/TITLE\ "//'|sed 's/^[ \t]*//'|sed '
s/"//'`
#|sed 's/ /\\ /g'`
CDPERFORMER=`less "$CUEFILE"|grep -B10 FILE|grep PERFORMER|sed 's/PERFORMER\ "//'|sed 's/^[ \
t]*//'|sed 's/"//'`
TRACKTITLE=`less "$CUEFILE" |grep -A4 TRACK\ $TRACKNUMBER|grep TITLE|sed 's/TITLE\ "//'|sed '
s/^[ \t]*//'|sed 's/"//'`
PERFORMER=`less "$CUEFILE" |grep -A4 TRACK\ $TRACKNUMBER|grep PERFORMER|sed 's/PERFORMER\ "//
'|sed 's/^[ \t]*//'|sed 's/"//'`

echo "CD Performer: $CDPERFORMER"
echo "CD Title: $CDTITLE"
echo "Track Title: $TRACKTITLE"
echo "Track Performer: $PERFORMER"


echo $CDPERFORMER $CDTITLE
echo $TRACKNUMBER $TRACKTITLE

output:
Quote:
$ ../trackname.sh 2 Santana\ -\ Abraxas.cue
Track Number: 02
CD Performer: Santana
CD Title: Abraxas
Track Title: Black Bagic Woman - Gypsy Queen
Track Performer: Santana
Abraxas
02 Black Bagic Woman - Gypsy Queen
why doesn't the second to last "echo" command work properly?

some more oddity, if I replace the last two echo commands with:
Code:
echo "\"$CDPERFORMER\""
echo "\"$CDTITLE\""
echo "\"$TRACKNUMBER\""
echo "\"$TRACKTITLE\""

I get:
Quote:
"Santana
"Abraxas
"02"
"Black Bagic Woman - Gypsy Queen
or with:
Code:
echo "\"$CDPERFORMER\" "
echo "\"$CDTITLE\" "
echo "\"$TRACKNUMBER\" "
echo "\"$TRACKTITLE\" "

I get:
Quote:
" antana
" braxas
"02"
" lack Bagic Woman - Gypsy Queen
When all I want is an output echo (or really a variable with the following so i can use it in a mv command):
"Santana - Abraxas - 02 - Black Bagic Woman - Gypsy Queen"

anyone know what I'm doing wrong? thanks!!
# 2  
Old 03-23-2008
Have you tried something simple like:
Code:
echo "$CDPERFORMER - $CDTITLE - $TRACKNUMBER - $TRACKTITLE"

# 3  
Old 03-24-2008
Quote:
Code:
echo "\"$CDPERFORMER\" "
echo "\"$CDTITLE\" "
echo "\"$TRACKNUMBER\" "
echo "\"$TRACKTITLE\" "

I get:
This funny board software didn't even know how to quote the output, so I take that as additional indication that the problem is this: you have DOS carriage returns in the output.

I really wonder about your use of less inside a script. Does it bring some benefit over simply reading the file?

Quote:
Code:
CDPERFORMER=`less "$CUEFILE"|grep -B10 FILE|grep PERFORMER|sed 's/PERFORMER\ "//'|sed 's/^[ \
t]*//'|sed 's/"//'`

With all due respect, you should probably read up on sed scripting. grep | sed is almost always redundant, since sed is basically a grep on stereoids.

Code:
CDPERFORMER=`grep -B10 FILE "$CUEFILE" |
    tr -d '\015' |
    sed -n 's/^[ 	][ 	]*PERFORMER[ 	][ 	]*"\([^"]*\)*"/\1/p'`

... assuming that your repeated sed invocations were meant to remove any PERFORMER tag, remove any leading whitespace before it, and trim the double quotes around the value (and throwing in the removal of any DOS carriage returns as a bonus). Probably the first grep could also be avoided if you familiarize yourself with sed some more, but this is how far I get without even reading the manual page. (Granted, the real magic is in being able to write a proper regular expression for any given problem.) ... That's a tab and a space between the square brackets, by the way.
# 4  
Old 03-24-2008
Quote:
Originally Posted by redhead
Have you tried something simple like:
Code:
echo "$CDPERFORMER - $CDTITLE - $TRACKNUMBER - $TRACKTITLE"

yes, sorry, forgot to show what that output, which was basically the tracknumber and the tracktitle, ie:
Quote:
02 - Black Bagic Woman - Gypsy Queen
(from memory, i believe there were some spaces before the 02, but nothing else if anything).
# 5  
Old 03-24-2008
Java

Quote:
Originally Posted by era
This funny board software didn't even know how to quote the output, so I take that as additional indication that the problem is this: you have DOS carriage returns in the output.
I'm running linux, why would I have DOS carriage returns?

Quote:
I really wonder about your use of less inside a script. Does it bring some benefit over simply reading the file?

With all due respect, you should probably read up on sed scripting. grep | sed is almost always redundant, since sed is basically a grep on stereoids.
yea, except I don't really know how to use sed outside of how I've used it.

Quote:
Code:
CDPERFORMER=`grep -B10 FILE "$CUEFILE" |
    tr -d '\015' |
    sed -n 's/^[ 	][ 	]*PERFORMER[ 	][ 	]*"\([^"]*\)*"/\1/p'`

... assuming that your repeated sed invocations were meant to remove any PERFORMER tag, remove any leading whitespace before it, and trim the double quotes around the value (and throwing in the removal of any DOS carriage returns as a bonus). Probably the first grep could also be avoided if you familiarize yourself with sed some more, but this is how far I get without even reading the manual page. (Granted, the real magic is in being able to write a proper regular expression for any given problem.) ... That's a tab and a space between the square brackets, by the way.
repeated sed was indeed to do basically all that.
yea, the first grep could probably be avoided, but I don't know how exactly.

still doesn't explain why my desired output is not working though.
of course, any help with sed would be appreciated. I've tried reading some of the online FAQ's, etc. but they all seem to assume some knowledge which I am not privy to...
# 6  
Old 03-24-2008
Did you try trimming the assumed carriage returns from the file? If something is fetching data from the Internet then the protocol is probably using carriage returns, and they might survive into your files (depending on the client which fetches them).

There's a book about awk & sed from O'Reilly, it's very old but also very much worth reading. Also most Unix intro books have a few chapters dedicated to regular expression tools in general, and grep and sed in particular, then moving on to awk. The manual page is not particularly gruesome, either, although of course it's primarily intended as a reference, not a tutorial.
# 7  
Old 03-24-2008
Quote:
Originally Posted by era
Did you try trimming the assumed carriage returns from the file? If something is fetching data from the Internet then the protocol is probably using carriage returns, and they might survive into your files (depending on the client which fetches them).
well that was it, the original source of the information was from a dos file. I ran dos2unix on it and ran the script and it worked fine.


Quote:
Originally Posted by era
There's a book about awk & sed from O'Reilly, it's very old but also very much worth reading. Also most Unix intro books have a few chapters dedicated to regular expression tools in general, and grep and sed in particular, then moving on to awk. The manual page is not particularly gruesome, either, although of course it's primarily intended as a reference, not a tutorial.
I'll have look into it, thanks for the help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep two files: -F flag gives weird output

Hi Members, I'm confused with grep -F option. Goal is to get all the lines from file2 that have exact gene name from gene list (file one). File one has list of genes: File two has lot more information pertinent to genes in file one: I use three following commands: 1) grep -wf gene... (9 Replies)
Discussion started by: genome
9 Replies

2. UNIX for Advanced & Expert Users

Weird output from ps command

Hi Guys, I am regular Solaris user. I came across a weird problem that puzzled me. Hope you guys can help. I found that process's state(command & arguments) in two different variants of ps command is different. Can anyone explain how is this possible? bash-3.2$ ps -eLo pid,s,comm,args |... (2 Replies)
Discussion started by: brij123
2 Replies

3. HP-UX

[Solved] Weird 'ls -l' output

Hello folks, I've found an HP-UX server with a rare 'ls -l' output. Please see the attached file. Anybody knows how can I change the output to not have this extra tabulations? Thanks in advance! (10 Replies)
Discussion started by: carpannav
10 Replies

4. Shell Programming and Scripting

Weird tail output over ssh

Hello; Am trying to correct the formatting of tail output over ssh. Using the following code: echo "" > $FILE for BOX in $SERVERS do echo "Processing on $BOX" |tee -a $FILE echo "===============================" >> $FILE sudo ssh $BOX 'TERMINAL="vt100" /usr/bin/sh -s' <... (2 Replies)
Discussion started by: delphys
2 Replies

5. Shell Programming and Scripting

Traceroute script weird output

This script is giving weird output #!/bin/bash NETPATH=(`/bin/traceroute -n 4.2.2.2 | awk '{print $2}'`) for i in "${NETPATH}" do echo $i done The output: to 11.11.11.1 1.1.1.1 99.111.208.2 traceroute_test.sh traceroute_test.sh (7 Replies)
Discussion started by: thumbs
7 Replies

6. Shell Programming and Scripting

In bash getting weird output from function ?

My script- result="" times() { echo "inside the times function" result=8 echo "Inside function $result" return $result } result=$(times) echo "the value is "$? echo "the value of result $result" when I run I get this, why the value still remain 0. $ ./func the value is 0 the value... (5 Replies)
Discussion started by: boy18nj
5 Replies

7. UNIX for Dummies Questions & Answers

weird 'ls' output

Hi, Anyone knows why I can't display the contents of my directory and how to fix this? http://i50.tinypic.com/4smfth.jpg Thanks in advance for any advise. Deanne Double post. Continued here. (0 Replies)
Discussion started by: Deanne
0 Replies

8. Shell Programming and Scripting

format of output is weird

hi all, have a ksh script which connects to a database and runs a sql and dumps it to a '.csv' file. The problem is the result is in multiple rows with long spaces in between when it should be just a single line and this screws up the format in the '.csv' file. script is : #!/bin/ksh... (1 Reply)
Discussion started by: cesarNZ
1 Replies

9. UNIX for Dummies Questions & Answers

Weird character in between echo function

Hi All, Appreciate if anyone can help. I've a script where it does echo function like this while do FILE_ARG="cu0${w}_${FILE}_${DT}.av" ORACLE_ERROR=`grep "ORA-" ${FILE_ARG}` if ]; then Func_Log_Writer "Fail! ${FILE_ARG}\n" Func_Log_Writer "Error message:... (2 Replies)
Discussion started by: agathaeleanor
2 Replies

10. AIX

Weird bootlist output

just setup a new system today - 9117 570, using HMC for console but not partitioned. I installed this system twice. the first time it started off as 5300-00, then updated to ML03. before the update, I believe I mirrored the rootvg, and then altered the bootlist, at that point, the display was... (4 Replies)
Discussion started by: davew1099
4 Replies
Login or Register to Ask a Question