bash n flac

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash n flac
# 8  
Old 11-28-2007
Originally Posted by bakunin
Perderabo has always told you how to solve the find problem - sorry for my sloppiness.
I'm the one who is sorry.. Sorry at coding Smilie That line was a big help!

Originally Posted by bakunin
Still, the above lines give me headaches: why use two different tools for a purpose where one would suffice?

part1="$(sed -n '/ARTIST/ {;s/^.*=//;s/ /_/g;p;}' tmp/tmp.txt)"
part2="$(sed -n '/TITLE/ {;s/^.*=//;s/ /_/g;p;}' tmp/tmp.txt)"

does the same.

Just my misunderstanding of what you said earlier.
I thought you meant that any time that a .* was used,
it would be safer to use a pipe. This Awk/Sed example by Trumpen was
the only thing I could find that did what I wanted.
After re-reading your post I now understand that it is meant
only for input.

I'm in the middle of adding the error checks mentioned earlier, After I
get it done, I will put it up here for other's to peruse and/or use as needed.

Thanks again all!!
# 9  
Old 11-29-2007
You can do it as a single command with awk, too:

part1=$(awk -F= '/ARTIST/{gsub(" ","_");print $2}' tmp/tmp.txt)
part2=$(awk -F= '/TITLE/{gsub(" ","_");print $2}' tmp/tmp.txt)

# 10  
Old 11-29-2007
Originally Posted by vbslim
I thought you meant that any time that a .* was used, it would be safer to use a pipe.
This concept is a bit hard to grasp, because an asterisk is seemingly the same as an asterisk. No, that isn't the case.

There are regular expressions which are interpreted by regexp-using programs: sed, awk, grep, ed, vi, ... In this set of regular expressions a "." stands for "any character" and the asterisk stands for "0 or more of the last expression". ".*" means therefore "any number (including 0) of any character" and will therefore match any string whatsoever. Its the "real big joker", so to say.

But all these regexps deal with *string* manipulation. You feed a string to the program and this regexp will decide if the string matches or not. In this regard awk, sed and the others work basically the same way: if the string matches (of if it doesn't match) then a certain action is performed on this string, otherwise it isn't. (If i got you interested: Dale Dougherty wrote an excellent book, "sed & awk".)

Something entirely different are *shell* wildcards. They are some sort of regular expressions too, but their meaning is another. In this set of regexps the asterisk means "any number of any characters", similar to ".*" above.

The reason, why shell expansion poses a risk is the following: suppose a commandline like

ls -l *txt

In OSes like DOS the options ("-l", "*txt") would be passed to the program, in this case the executable "ls", and ls would have to figure out if a filename matches the schema and should be displayed or not. Not so in Unix: the shell (the program you type the command into) itself will expand the wildcard and replace what you have typed by what is matched by what you typed.

Suppose there are two files "a.txt" and "b.txt" in the directory and you issue the above command. First the shell will notice the wildcard, look into the directory and find 2 files which match it. Then it will replace your command with:

ls -l a.txt b.txt

and this is, what ls will finally see. If you had entered the command this way yourself ls would not be able to tell the difference.

Now, suppose you would enter the same command in a directory where several hundreds of files matching the wildcard reside. The commandline would become pretty long, yes? Unfortunately the commandline has a limit (4k characters) and ls has also a limit. More than a certain number of arguments will not be digested. "Too many arguments" or "Argument list too long" reads the error which will be displayed then.

I hope this clarifies it.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

3. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

4. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

5. UNIX for Dummies Questions & Answers

Im new to bash scriping and i found this expression on a bash script what does this mean.

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
Discussion started by: kevin298
1 Replies

6. Shell Programming and Scripting

Using arrays in bash using strings to bash built-in true

I have the following code and for some reason when I call the program using /home/tcdata/tatsh/trunk/hstmy/bin/bash/raytrac.bash --cmod=jcdint.cmod I get hasArgument = hasArgument = true Somehow the array element is returning even though I have not chosen the option. ... (41 Replies)
Discussion started by: kristinu
41 Replies

7. Shell Programming and Scripting

automatic script for flac to mp3 conversion

used flac2mp3 (0 Replies)
Discussion started by: barrydocks
0 Replies

8. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

9. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies
Login or Register to Ask a Question