Help me in Grep Command + cd command in single line
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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*
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"*
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.