Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This 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!


  Search this Thread
Old 05-25-2008, 07:22 AM   #1
LQ Newbie
Registered: May 2008
Posts: 2

Rep: Reputation: 0
Unhappy 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
Old 05-25-2008, 07:44 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657
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"*
Old 05-27-2008, 03:28 AM   #3
LQ Newbie
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Post 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.
Old 05-27-2008, 04:16 AM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
shell script/command for converting columns/table onto a single line skuz_ball Programming 9 11-30-2007 03:02 AM
a single command the spans more then 1 line bourne Programming 4 11-27-2007 05:50 AM
Command line tool to find(1) or grep(1) faster? rsheridan6 Linux - Software 2 02-18-2006 03:50 PM
Command line screenshot of a single window Hko Programming 1 12-02-2005 09:21 AM

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration