LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help me in Grep Command + cd command in single line (http://www.linuxquestions.org/questions/linux-newbie-8/help-me-in-grep-command-cd-command-in-single-line-644631/)

JeiPrakash 05-25-2008 08: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.,
pwd=/home/Jei
i want command like path=cd $pwd | grep 'jobname' O*

will the above command work

jschiwal 05-25-2008 08: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:
DIR=/home/jei
cd ${DIR} ; grep 'jobname' O*

or

DIR=/home/jei
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:
dir=$1
cd ${dir} && grep 'jobname' "${dir}/O"*

JeiPrakash 05-27-2008 04:28 AM

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


#!/bin/sh
Home=/sample/docs/learn
Met_path=$Home/$1
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 05:16 AM

Jei;
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 04:33 AM.