Computing.Net > Forums > Unix > Need to grep one word, cut can't do it

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need to grep one word, cut can't do it

Reply to Message Icon

Name: 4el
Date: July 2, 2002 at 08:37:55 Pacific
Comment:

How can i grep only one word from a file, not the whole string, if i dont have fixed position ( cut cannt help me)

Ex.
11,40 * * * * /usr/local/bin/apache_test.sh -s

i need only script name as variable, but position is always another (crontab)
BIG THANKS
4el



Sponsored Link
Ads by Google

Response Number 1
Name: LANkrypt0
Date: July 2, 2002 at 09:33:09 Pacific
Reply:

Id do it a messy, but it would work

grep "word" file | tr "[ ]" "[\n]" | grep "word"


0

Response Number 2
Name: James Boothe
Date: July 2, 2002 at 12:36:37 Pacific
Reply:

Actually, that was pretty creative. The following awk solution will print each word in the file that contains a slash. It could easily be adjusted to print only the first qualifying word in each line, or whatever:

awk '{for (w=1;w<=NF;w++) \
if (match($w,"/")) \
print $w}' myfile


0

Response Number 3
Name: LANkrypt0
Date: July 2, 2002 at 12:55:51 Pacific
Reply:

Aye, the example I gave can also be easily modified (forgot to mention that)

In thr first bracket put a slash:

grep "word" file | tr "[/]" "[\n]" | grep "word"

And that would also work fine


0

Response Number 4
Name: 4el
Date: July 3, 2002 at 00:11:56 Pacific
Reply:

cool, but i made a small mistake, i need the whole path to the script:) sorry boys, how can i do this?:)
output must be smt like this -> /usr/local/apache_test.sh, a not a single word. Any idea?

BIG THANKS (Episode II)


0

Response Number 5
Name: 4el
Date: July 3, 2002 at 00:41:47 Pacific
Reply:

and smt more :) it can be a flag after script that i dont need, so how can have only the path, smt like grep from slash until space. thx


0

Related Posts

See More



Response Number 6
Name: LANkrypt0
Date: July 3, 2002 at 06:29:48 Pacific
Reply:

If its going to be the path everytime, all you need to do is use grep to produce that line then awk:

awk '{print $6}'

To print that path and the scriptname.


0

Response Number 7
Name: Frank
Date: July 5, 2002 at 07:11:46 Pacific
Reply:

Only to complete the statment from LANKrypt0

awk '/apache/ {print $6}' crontab

No RISK no fun
Frank


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Need to grep one word, cut can't do it

Can't compile Stevens code from apu www.computing.net/answers/unix/cant-compile-stevens-code-from-apu/5931.html

Get the last few words of a line? www.computing.net/answers/unix/get-the-last-few-words-of-a-line/7459.html

Bourne shell script,Unix www.computing.net/answers/unix/bourne-shell-scriptunix/5366.html