-   Linux - Newbie (
-   -   Help me in Grep Command + cd command in single line (

JeiPrakash 05-25-2008 07:22 AM

Help me in Grep Command + cd command in single line
Can anyone help me in filtering the job name thru grep command.The command also should have cd.
for eg.,
i want command like path=cd $pwd | grep 'jobname' O*

will the above command work

jschiwal 05-25-2008 07:44 AM

This doesn't really make sense.
path=cd $pwd
This will set the variable "path" to the string "cd" and then try to run a $pwd command which isn't a command.

And what do you mean by job name, and how is cd'ing to a directory going to print it out?

Without the pipe, "grep 'jobname' O*" will find lines of text in files starting with 'O' that have the word jobname in them.

Maybe you want:
cd ${DIR} ; grep 'jobname' O*


grep 'jobname' $DIR/O*

or simply

grep 'jobname' /home/jei/O*

If the directory isn't a constant, such as an argument to a script you might do something like:
cd ${dir} && grep 'jobname' "${dir}/O"*

JeiPrakash 05-27-2008 03:28 AM

Help in Grep Command
Thanks but there are few things that i need to explain i think.

job= cd ${Met_path}|`grep 'WM_EOH_HN' O* |cut -d : -f 1`
start_time= `head -6 $job | tail -1 |cut -d '' -f 1-3`
echo $start_time

This is the code that i go for. What i planned to do is i have job name that has the job name as 'WM_EOH_HN' and i am taking the name of the job and from that taking the starting time and printing it.

pixellany 05-27-2008 04:16 AM

I would advise you to try the various commands one at a time. Once you understand them, then you can put them together.

First, jschiwal already explained that this will not work:
job=cd $xyz
Try it yourself so that you understand why.

Next, you have this:
`grep ....|cut ....`
This make no sense. The backtics are used to pass the result of a command to something else. For example:
list=`ls -l` would list the current directory and assign the results to the variable "list". In you case, you do not use the value of the expression inside the backtics.

All times are GMT -5. The time now is 07:28 PM.