LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-06-2013, 03:41 PM   #1
bvdv
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Rep: Reputation: Disabled
find exec to grep problem


Hello all,
thanx in advance for trying to help me.

my problem is that i cant direct my output to i file.
i think it has to do with the space in my directory/filenames
the output i get on the screen(green) is what i want in the test.txt file

again thx for all help
Bert


sudo find '/home/bert/Music/The Offspring' -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" -exec /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount {} + | grep "bert" > test.txt
105,469 /home/bert/Music/The Offspring/13 - Keep Them Separated.mp3
91,4685 /home/bert/Music/The Offspring/14 - No Brakes.mp3
113,582 /home/bert/Music/The Offspring/04 - Walla Walla.mp3
107,666 /home/bert/Music/The Offspring/10 - Why Donīt You Get a Job.mp3
105,469 /home/bert/Music/The Offspring/02 - The Kids Arenīt Alright.mp3
103,359 /home/bert/Music/The Offspring/09 - Original Prankster.mp3
90,6661 /home/bert/Music/The Offspring/06 - The Meaning of Life.mp3
139,675 /home/bert/Music/The Offspring/16 - Change the World.mp3
105,469 /home/bert/Music/The Offspring/03 - Sheīs Got Issues.mp3
114,844 /home/bert/Music/The Offspring/07 - Staring at the Sun.mp3
101,333 /home/bert/Music/The Offspring/05 - Want You Bad.mp3
94,8251 /home/bert/Music/The Offspring/01 - Americana.mp3
96,5975 /home/bert/Music/The Offspring/11 - Gone Away.mp3
94,8251 /home/bert/Music/The Offspring/15 - Million Miles Away.mp3
118,804 /home/bert/Music/The Offspring/08 - Self Esteem.mp3
95,7031 /home/bert/Music/The Offspring/12 - Pretty Fly (For a White Guy).mp3
 
Old 08-06-2013, 03:49 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Is - /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount - executable?

What output does it produce?

Explain what you mean by "can't direct output to file" - what is actually happening?
 
Old 08-06-2013, 04:01 PM   #3
bvdv
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
when i execute the command (blue)
i get the green text on the screen.
what i want is the green text in a file ( here test.txt) ( so redirect green in the test.txt file)

bert
 
Old 08-06-2013, 04:12 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
OK, sorry, I thought the green was what you wanted but were not getting anything...

I can only guess that the .../bpmcount is maybe writing somewhere other than stdout so that it is not seen by the pipe at all.

[EDIT]
What does ls -l test.txt say? test.txt isn't possibly a FIFO is it?
[/EDIT]

Last edited by astrogeek; 08-06-2013 at 04:14 PM.
 
Old 08-06-2013, 04:24 PM   #5
bvdv
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
$ ls test.txt
test.txt
sorry
$ ls -l test.txt
-rw-rw-r-- 1 bert bert 0 aug 6 23:23 test.txt


bert

Last edited by bvdv; 08-06-2013 at 04:26 PM.
 
Old 08-06-2013, 04:26 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
That was

Code:
ls -l test.txt
You write faster than I do!
 
Old 08-06-2013, 04:29 PM   #7
bvdv
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
same for >>

$ sudo find '/home/bert/Music/The Offspring' -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" -exec /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount {} + | grep "bert" >> test.txt

$ ls -l test.txt
-rw-rw-r-- 1 bert bert 0 aug 6 23:23 test.txt
 
Old 08-06-2013, 04:30 PM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Question:

Is this one path, or two separate scripts?

Code:
-exec /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount {}

or

-exec /home/bert/Documents/bmpcount [SPACE] /usr/lib64/bpmdj/bpmcount {}
 
Old 08-06-2013, 04:31 PM   #9
bvdv
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
one
the bpmcount executable is in the /home/bert/Documents/bmpcount/usr/lib64/bpmdj/ directory

Bert
 
Old 08-06-2013, 04:35 PM   #10
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Is the bpmcount a binary or shell script?

If it is a shell script, and not too long, can you post it here?

My guess is that it is not writing to stdout, so grep never sees it.

[EDIT]
Try this
Code:
sudo find '/home/bert/Music/The Offspring' -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" -exec /home/bert/Documents/bmpcount
/usr/lib64/bpmdj/bpmcount {} + | grep "bert" 2> test.txt
[/EDIT]

Last edited by astrogeek; 08-06-2013 at 04:40 PM.
 
Old 08-06-2013, 04:41 PM   #11
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
just try adding 2>&1
Code:
sudo find '/home/bert/Music/The Offspring' \
            -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" \
            -exec /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount {}\
             2>&1 + \
            | grep "bert" >> test.txt
Edit you probably don't even need the grep
Code:
sudo find '/home/bert/Music/The Offspring' \
            -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" \
            -exec /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount {}\
             2>&1 + >> test.txt

Last edited by Firerat; 08-06-2013 at 04:43 PM.
 
Old 08-06-2013, 04:43 PM   #12
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
In case it is not writing to stdout, you can find out if redirecting using "2>file" works (redirect stderr).

Assuming you are using bash of course. If csh/tcsh try ">&file" which will redirect both of them.
 
Old 08-06-2013, 04:57 PM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
If redirecting stderr does not work (2>, 2>&1, etc.) you might check bpmcount to see if it is doing something screwy like writing to /dev/console or some such place.
 
Old 08-06-2013, 05:14 PM   #14
bvdv
LQ Newbie
 
Registered: Aug 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
sorry for the late reply
@astrogeek
sudo find '/home/bert/Music/The Offspring' -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" -exec /home/bert/Documents/bmpcount
/usr/lib64/bpmdj/bpmcount {} + | grep "bert" 2> test.txt
does not work no text in test.txt

@firerat
You are right about the grep the 2 lines of code produces the same test.txt(oragne color).
but not exactly what i want
as you can see there are lines with th progress thats why i used the grep for "filtering" the lines that does contains a directory with my name"bert"
105,469 /home/bert/Music/The Offspring/13 - Keep Them Separated.mp3.

but we are getting closer :-)




0%
1%
2%
3%
<snip>
100%
101%
102%
103%
104% 105,469 /home/bert/Music/The Offspring/13 - Keep Them Separated.mp3

0%
1%
2%
<snip>
100%
101% 91,4685 /home/bert/Music/The Offspring/14 - No Brakes.mp3

Last edited by bvdv; 08-06-2013 at 05:38 PM.
 
Old 08-06-2013, 05:26 PM   #15
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
please snip your post..

10%
20%
<snip>
100%
would tell us enough

going to use > , instead of >> ( replace instead of add to )
Code:
sudo find '/home/bert/Music/The Offspring' \
            -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" \
            -exec /home/bert/Documents/bmpcount/usr/lib64/bpmdj/bpmcount {}\
             2> test.stderr > test.txt +
you will get two files,

Last edited by Firerat; 08-06-2013 at 05:28 PM.
 
  


Reply



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] how to use cp find and grep together to copy a list of files using find with grep babhijit Linux - Newbie 10 07-03-2013 12:25 PM
Problem Searching for php files with Find and Grep ssmela Linux - General 3 11-02-2010 01:55 PM
[SOLVED] Problem with variable in find -exec {} ziphem Linux - Newbie 5 10-20-2010 03:09 PM
Find with -exec argument - not giving proper output..how to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
Bash scripting question with find and grep and .bashrc - a multi year problem brfindla Linux - Software 9 08-24-2009 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:31 AM.

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