Another computer question...

OP
Black Hole

Black Hole

May contain traces of nut
I see, you're invoking another bash session inside the loop. Can that command be run on a command line, or does it have to be in a script file?

There are loads of %whatevers you can do these days to stop you making the mess in the first place.
Interesting. This stuff post-dates when I was actively writing .bat files, so I'm not really aware of it. We used to have to install third-party command extension packages, which you could never assume would be present on another system so I didn't use them.
 

prpr

Well-Known Member
I see, you're invoking another bash session inside the loop.
Only to make the redirection work. There's bound to be at least one different way of doing it (which may or may not be better).
Can that command be run on a command line, or does it have to be in a script file?
Either.
We used to have to install third-party command extension packages, which you could never assume would be present on another system so I didn't use them.
Indeed, but M$ finally woke up and implemented some more useful stuff.
 

af123

Administrator
Staff member
This should be fine up to a certain number of files:
Bash:
for f in *.txt; do
    cat "$f" > "$f.out"
done

Otherwise you need something like
Bash:
find . -name '*.txt' -type f | while read f; do
    cat "$f" > "$f.out"
done
 
OP
Black Hole

Black Hole

May contain traces of nut
This should be fine up to a certain number of files:
Bash:
for f in *.txt; do
    cat "$f" > "$f.out"
done
That seems to be missing a semicolon before the done.

Edit: Aha! Maybe not. Is it the case that a line break implies a ;?
 

prpr

Well-Known Member
Yes. I just discovered this effect too, if you type in the following:
Code:
prpr@mint ~ $ for f in *.exe
> do echo $f
> done
vncviewer.exe
and then press the Up-arrow key you get it automagically converted:
Code:
prpr@mint ~ $ for f in *.exe; do echo $f; done
 
OP
Black Hole

Black Hole

May contain traces of nut
For the record:

I was looking for a way to get a hex dump of a file into a text file or output to printer; the Notepad++ hex extension displays a hex dump but damned if I can find a way to grab/print it (except as a screen shot). MS-DOS used to have a hex editor (DISKEDIT?) but this doesn't seem to be available as a Windows terminal command. Googling produced this:

Code:
certutil -encodehex <input> <output>
 
OP
Black Hole

Black Hole

May contain traces of nut
And the reason the above is relevant to me...

I need a way of extracting the Genre ID3 tag from a .mp3 to stdout on the command line, something like:
Code:
> id3genre test.mp3
Country
>

I've looked at loads of utilities available online, but they all have wrinkles, or would require me to extract the output I want from a messier output.

I don't need Rolls Royce, all the input .mp3s conform to the same "simple" tag structure (all generated by the same software, no quirks), with the tags at the start of the file (not the end!), so the algorithm goes something like this:
  1. Check the file starts with ASCII byte sequence "ID3";
  2. Locate first occurrence of ASCII byte sequence "TCON";
  3. Read a string character count n;
  4. At a fixed offset, read n characters (16-bit Unicode, but all ASCII);
  5. Convert to ASCII and output to StdOut.
If I were doing this I would start with Awk, but I reckon it should be a piece of piss to anyone up to speed with C (or something) to knock up id3genre.exe.

Any takers? I'll supply a sample file if so.

Detailed spec:
  1. Read 10 bytes from input to array H[1:10]
  2. If H[1:3] != "ID3" (49 44 33) exit
  3. Count1 = (((H[7]&127)*128+(H[8]&127))*128+(H[9]&127))*128+(H[10]&127)
  4. Set array G = empty
  5. While Count1 > 0 do
    1. Read 10 bytes from input to array H[1:10]
    2. Count1 = Count1 - 10
    3. Count2 = ((H[5]*256+H[6])*256+H[7])*256+H[8]
    4. If H[1:4] = "TCON" (54 43 4F 4E) do
      1. Read Count2 bytes from input to array G
      2. Count1 = 0
    5. Else
      1. Read Count2 bytes from input and discard
      2. Count1 = Count1 - Count2
    6. Endif
  6. Loop
  7. Index = 4
  8. While G[Index] exists do
    1. Output G[Index]
    2. Index = Index + 2
  9. Loop
 
Last edited:
Top