Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

print from a string to the end of line

print from a string to the end of line

print from a string to the end of line

input from ps can be:
user 29976 29787 2 16:45 ? 00:00:00 rsync -H --timeout=60 --force -av --no-owner --no-group --log-file=/tmp/rsync.1448639132.log --include-from=/tmp/sycnzKVqT ....
but options can also be in another order, like:
user 29976 29787 2 16:45 ? 00:00:00 rsync -H --timeout=60 --force -av --log-file=/tmp/rsync.1448639132.log --no-owner --no-group --include-from=/tmp/sycnzKVqT ....

i need to get what log name is used the the running rsync

i could do it using awk if the position is always the same but don't know how to get it when it changes...

I was thinking to get all from field beginning with --log-file to the end of line, then i could easily get log file name using awk -F"[=| ]" ....

thx in advance for a hint.

RE: print from a string to the end of line


You mean like this ?


ps | awk -F '[= ]' '{for(i=1;i<=NF;i++)if($i=="--log-file"){print$++i;break}}' 
Yes, that seems to be the simplest solution, supposing the log file name will never contain space or equal sign.


RE: print from a string to the end of line


I'm sure feherke's is much more efficient, but I came up with this:

ps | awk -F'--log-file=' '/log-file/{print $2}' | awk '{print $1}'



RE: print from a string to the end of line


A short off-topic one with GNU grep inspired by John's solution :


ps | grep -Po '(?<=--log-file=)\S+' 
I wish Awk to understand PCRE once.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close