LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script (https://www.linuxquestions.org/questions/programming-9/bash-script-65241/)

brian0918 06-12-2003 03:12 PM

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

acid_kewpie 06-12-2003 03:18 PM

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??

Proud 06-12-2003 03:18 PM

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'.

ranger_nemo 06-12-2003 03:24 PM

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)

brian0918 06-12-2003 03:25 PM

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??


brian0918 06-12-2003 03:30 PM

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. :newbie:

brian0918 06-12-2003 04:08 PM

bleh

brian0918 06-12-2003 06:06 PM

Thanks for the help, I got the script to work.


All times are GMT -5. The time now is 07:50 AM.