LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-12-2003, 03:12 PM   #1
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Rep: Reputation: 15
bash script


I got this file progress titlebar updater thing to work, but now I want to go a step further:
Have it find what jobs are running, and append their progress to a file, and have that file be constantly updated and outputted. Right now, I'm just working on getting to the directory where the job was run from (in order to check the progress). What I currently have is:

myjobs | grep "bleh" | grep -v -e "blah" | awk '{ print $4 }' | find . -name `head -n 1` -printf %h

What this does is first output the jobs currently set up, one line at a time, then it takes the ones containing "bleh" and removes the lines containing "blah", then grabs the 4th column (which contains file names) and then returns the directory in which the first file in the list is located. What I would like to do now is switch to that directory. I tried doing this:

myjobs | grep "bleh" | grep -v -e "blah" | awk '{ print $4 }' | cd `find . -name `head -n 1` -printf %h`

but it gave these errors:

find: missing argument to `-name'
bash: -printf: command not found
bash: cd: head: No such file or directory

Is there an easier way to do this?


Also - If I am going to get this to work, I need to be able to count the number of rows once "bleh" has been extracted and "blah" has been removed, then be able to repeatedly "sed -e '1d'" to remove the first line and then do the process again (cd to directo
 
Old 06-12-2003, 03:18 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
can we please keep these in one thread... this is what.. the fourth thread for this issue?

those errors then:

you are trying to run two nested backticked commands, the first ` will start the command, but the next one, which you believe will give a second command for the find will end the current one. you want

cd ( find . -name ( head -n 1 ) -printf %h )

but you're actually doing:

cd ( find . -iname ) head -n 1 ( -printf %h )

which makes even less sense. you have also provided no data for that head command if it did work... what is head meant to print the first line of??

Last edited by acid_kewpie; 06-12-2003 at 03:19 PM.
 
Old 06-12-2003, 03:18 PM   #3
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
Maybe try "find ./ 'head -n 1' -print %h" or man find and head to check how you have to quote those arguements. Or use a variable instead of 'head -n 1'.
 
Old 06-12-2003, 03:24 PM   #4
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
If you want to use command substitution, you need to write the one command as if it was a variable...

command1 $(command2)

example: cd /home/$(whoami)
 
Old 06-12-2003, 03:25 PM   #5
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
This isn't the same issue, I'm making something different and better.
head does what it says, it grabs the first line of the text that is left.

When I do:
myjobs | grep "bleh" | awk '{ print $4 }' | find `head -n 1`

it correctly searches for and finds the file whose name matches the first line, fourth column of the text that's left from the output of "myjobs" after the lines containing "bleh" have been extracted.


Quote:
Originally posted by acid_kewpie
can we please keep these in one thread... this is what.. the fourth thread for this issue?

those errors then:

you are trying to run two nested backticked commands, the first ` will start the command, but the next one, which you believe will give a second command for the find will end the current one. you want

cd ( find . -name ( head -n 1 ) -printf %h )

but you're actually doing:

cd ( find . -iname ) head -n 1 ( -printf %h )

which makes even less sense. you have also provided no data for that head command if it did work... what is head meant to print the first line of??
 
Old 06-12-2003, 03:30 PM   #6
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by ranger_nemo
If you want to use command substitution, you need to write the one command as if it was a variable...

command1 $(command2)

example: cd /home/$(whoami)
Thanks for the helpful reply. I'm trying to do what you said, but it's not working. I've tried:

myjobs | grep "bleh" | awk '{ print $4 }' | cd $(find . -name `head -n 1` -printf %h)

and also:

myjobs | grep "bleh" | awk '{ print $4 }' | cd $(find . -name $(head -n 1) -printf %h)

as well as:

myjobs | grep "bleh" | awk '{ print $4 }' | cd `find . -name $(head -n 1) -printf %h`

but none of these are working for me.
 
Old 06-12-2003, 04:08 PM   #7
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
bleh

Last edited by brian0918; 06-12-2003 at 04:49 PM.
 
Old 06-12-2003, 06:06 PM   #8
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
Thanks for the help, I got the script to work.
 
  


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
Bash script moodupani Programming 3 08-30-2005 07:31 AM
Bash script Linh Programming 4 04-21-2004 05:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 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