You are not logged in.

#1 2012-07-20 15:37:28

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

[SOLVED]egrep+bash different results per console size

Greetings!

I apologize for the cluttered post, I'm not sure how to explain this in a more convenient manner. I have two pls files I want to parse with grep:

$ls *.pls
classic-rock-live.aac.pls  space.pls

I'd like to parse them, so I have lists of links from those files. I do this:

$ egrep -o http.* space.pls 
http://voxsc1.somafm.com:8200
http://mp2.somafm.com:8200

This works fine so far, but when I try to parse the other file, nothing happens, as in I get no output, just an empty line:

$ egrep -o http.* classic-rock-live.aac.pls

However, parsing both files at once works as expected:

$ egrep -o http.* *.pls
classic-rock-live.aac.pls:http://mp3channels.webradio.antenne.de/classic-rock-live.a
space.pls:http://voxsc1.somafm.com:8200
space.pls:http://mp2.somafm.com:8200

Besides the missing "ac", it should read "classic-rock-live.aac". I thought maybe the combination of i3 and urxvt ate something, so I made the terminal window fullscreen and tried again.

$ egrep -o http.* *.pls

space.pls:http://voxsc1.somafm.com:8200
space.pls:http://mp2.somafm.com:8200

Now the classic rock stuff is gone, only a blank line remains. Well, I thought, maybe it's the combination of urxvt and i3, i thought, so I tried the same command on a tty with the same result:

$ egrep -o http.* *.pls

space.pls:http://voxsc1.somafm.com:8200
space.pls:http://mp2.somafm.com:8200

Now it's getting interesting: When I used tmux to tile the window, so the width was smaller or equal the length of the string I expected, grep showed the string. The moment the string was shorter than the console width, grep showed nothing.

I stored the pls file here for forensic analysis.

Is this a known "feature"? I could not find anything about this behavior, maybe I'm just lacking the right keywords. What's going on?


I made another test:

$ egrep -o http://.* classic-rock-live.aac.pls | xargs
http://mp3channels.webradio.antenne.de/classic-rock-live.aac

It seems like grep actually parses the file correctly, but bash fails to display the output. Could anybody grab the file and make some tests, maybe on another distro as well, so I know whether to report a bug or not? Can anybody think of another test I could run to identify, whether it's bash or grep?

EDIT: A few generations of updates of most of the relevant packages fixed the problem.

Last edited by Awebb (2014-07-21 12:10:54)

Offline

#2 2012-07-20 15:44:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [SOLVED]egrep+bash different results per console size

I downloaded the linked file, and in urxvt running bash

~/downloads$ egrep -o http.* *.pls
http://mp3channels.webradio.antenne.de/classic-rock-live.aac

I also tested in xterm, same functional result.

Could there be an issue with the line-endings?  What happens if you cat the file in the terminal?

Last edited by Trilby (2012-07-20 15:45:04)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-07-20 15:55:58

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: [SOLVED]egrep+bash different results per console size

If I cat the file, everything is fine. I can use sed to manipulate the file.

Now I did this:

$ grep http://.*aac classic-rock-live.aac.pls 
File1=http://mp3channels.webradio.antenne.de/classic-rock-live.aac

grep suddenly shows the whole line. Note that it parses the whole line nevertheless, as we have proven by piping it into xargs.

Could you please, just for the sake of completeness, give the file name to grep as well, instead of *.pls'ing? I'm curious now.

EDIT: I also doublechecked to see if it writes the result in the same color as the background, it does not; there definitly is nothing. I also checked my .bashrc, but there was nothing of relevance.

Last edited by Awebb (2012-07-20 15:59:54)

Offline

#4 2012-07-20 16:04:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,332
Website

Re: [SOLVED]egrep+bash different results per console size

Odd.

Here you go:

$ egrep -o http.* classic-rock-live.aac.pls 
http://mp3channels.webradio.antenne.de/classic-rock-live.aac

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2012-07-20 17:13:21

dammannj
Member
Registered: 2009-01-28
Posts: 44

Re: [SOLVED]egrep+bash different results per console size

Strange stuff.

$egrep -o http.* *.pls
http://mp3channels.webradio.antenne.de/classic-rock-live.aac

$ egrep -o http.* classic-rock-live.aac.pls
http://mp3channels.webradio.antenne.de/classic-rock-live.aac

One thing I thought of though: do you have other files, specifically files named 'http.'*, in your directory?

Then this error is indeed understandable:

$ touch http.foobar; egrep -o http.* classic-rock-live.aac.pls

$ touch http.foobar; egrep -o 'http.*' classic-rock-live.aac.pls
http://mp3channels.webradio.antenne.de/classic-rock-live.aac

Quoting the expression is, in this case, essential.

Offline

#6 2012-07-20 17:24:22

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: [SOLVED]egrep+bash different results per console size

Nope, there are a few files in the folder, but nothing with http.

$ la
total 548K
drwxr-xr-x 3 itsme users 4,0K 20. Jul 17:58 .
drwxr-xr-x 5 itsme users 4,0K 18. Jul 10:27 ..
-rw-r--r-- 1 itsme users  179  5. Mai 2009  classic-rock-live.aac.pls
drwxr-xr-x 2 itsme users 4,0K 29. Jun 23:19 Doomicide-luakit-adblock-6ab1a92
-rw-r--r-- 1 itsme users 6,9K 18. Jul 21:20 Doomicide-luakit-adblock-6ab1a92.tar.gz
-rw-r--r-- 1 itsme users  378 17. Jul 23:52 space.pls
-rw-r--r-- 1 itsme users 519K 20. Jul 15:31 usenixsec2012-rubberhose.pdf

If it was just a wrong command, then the width of the terminal would not make a difference and xargs wouldn't produce output.

@Trilby: Thanks, it looks like I'm the only gay eskimo in my tribe this time. -.-

Last edited by Awebb (2013-07-08 15:03:46)

Offline

#7 2014-07-21 12:10:09

Awebb
Member
Registered: 2010-05-06
Posts: 6,688

Re: [SOLVED]egrep+bash different results per console size

Old thread cleanup day. I'm marking this ancient thread as solved. The machine does not exist anymore, I have not encountered the bug again after updating the device a couple of months later (but very well before). Whatever it was, an update fixed it long ago.

Offline

Board footer

Powered by FluxBB