Grep script name with path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep script name with path
# 1  
Old 11-19-2014
Grep script name with path

would like to grep everything from first occurrence of / until >(not includes)

example :

0 5 * * * /usr/local/bin/shell/test.sh >/tmp/test.log
Output would be : /usr/local/bin/shell/test.sh
# 2  
Old 11-19-2014
grep cannot extract substrings from lines...it works on whole lines and prints out whole lines but other like sed and awk can do so...
# 3  
Old 11-19-2014
Code:
echo '0 5 * * * /usr/local/bin/shell/test.sh >/tmp/test.log' | sed 's/^.[^\/]*//;s/ .*//'

I guess you'll want
Code:
crontab -l | sed 's/^.[^\/]*//;s/ .*//'

---------- Post updated at 08:58 PM ---------- Previous update was at 08:55 PM ----------

If you have the sample lines in a file, then
Code:
sed 's/^.[^\/]*//;s/ .*//' file

# 4  
Old 11-19-2014
Thanks and it worked
# 5  
Old 11-19-2014
Moderator's Comments:
Mod Comment Having two threads discussing the same problem is confusing for those volunteers trying to help you solve your problem and wastes everyone's time. It looks like you got different solutions, but they all work.

The other thread is here.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. Shell Programming and Scripting

Grep script name with path from crontab

I need help to grep file name with path from crontab ex : 0 5 * * * /tmp/test.sh 2>/tmp/test.log output : /tmp/test.sh Please use code tags next time for your code and data. Thanks (6 Replies)
Discussion started by: jhonnyrip
6 Replies

3. Shell Programming and Scripting

Need a perl script similiar to grep -r 'word' /path/to/dir"

Hi , i am looking for a perl script to grep for a string in all files inside a directory . bash command . grep -r 'word' /path/to/dir Thanks, Nvil (3 Replies)
Discussion started by: nevil
3 Replies

4. Shell Programming and Scripting

How to select the shortest path in grep search?

Hi, How can I display only one shortest path (A/B/configure)? $ grep configure file.txt A/B/configure A/B/C/configure A/B/C/D/configure Thank you. (9 Replies)
Discussion started by: hce
9 Replies

5. Shell Programming and Scripting

ls -l /directory/path | grep -f filter.txt NOT WORKING

Hi, I have been searching all over and cannot find a script or command that simply search or match the filenames listed in a file and match it from a directory. so far, example: cat filter.txt file1.def file2.conf file3.def ls -l /directory | grep -f filter.txt (15 Replies)
Discussion started by: wolf@=NK
15 Replies

6. Shell Programming and Scripting

script use min resource ( grep grep)

Hi i wrote script use it as watchdog ( i mean it check another program (pooya) whenever that was killed (closed or crashed) it run another script (pooya_start.sh) to start it, this script work fine and do the job for me , i need help of an expert to tell me (exact command) how to change this... (8 Replies)
Discussion started by: pooyair
8 Replies

7. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

8. UNIX for Dummies Questions & Answers

grep for a last word from a path

Hi , I want to get the last word from a path. Example:: I have path:: /TEMP_REGRESSION/regression/TESTSUITE/TestCases/Test1201/ext_libs/DATA/INTERNAL/pad_ext.lef I want the last word only.ie pad_ext.lef Please let me know how to grep that word. Thanks in advance (6 Replies)
Discussion started by: gujrathinr
6 Replies

9. Homework & Coursework Questions

How to use a execvp-call to do "grep PATH"?

Hello! I am learning how to use the function execvp. I have read through the UNIX manual. I have a process. I run execvp and I command it to do “printenv”. It works fine. Before I do the execvp-call I pipe STDOUT to go to a specific pipe. After that I restore STDOUT. I read that pipe in another... (2 Replies)
Discussion started by: andersbranderud
2 Replies

10. Shell Programming and Scripting

Maintain full path of a script in a var when sourcing it from a different script

Hi All, I've searched through the forum for a solution to this problem, but I haven't found anything. I have 2 script files that are in different directories. My first script, let's call it "/one/two/a.sh" looks like this: #!/bin/sh IN_DIR=`dirname $0` CUR_DIR=`pwd` cd $IN_DIR... (4 Replies)
Discussion started by: mrbluegreen
4 Replies
Login or Register to Ask a Question