truncate to end of line after a specific string
I thought this would be easy to find on google or figure out myself. But either I am not looking properly or missing the obvious. Apologies in advance if this has been replied elsewhere.
I want to delete all characters to end of line after a specific string in a file. So my file contents are such (with variable length lines) aaaabbbbbbbbbbbcccc.hrpt <www-alpha> dddddbbbbbbbbcccc.hrpt <www-beta> pppppppppppppppbbbbbbbbbbcccc.hrpt <www-gamma> xxxbbbbbcccc.hrpt <www-alpha> The common string above starts with is '.hrpt <www-' I want to delete everything and inclusive of the common string....so my output file would look like aaaabbbbbbbbbbbcccc dddddbbbbbbbbcccc pppppppppppppppbbbbbbbbbbcccc xxxbbbbbcccc I can easily do this using excel on a windows machine, but would like to try using shell scripting. I played around a bit with sed command with little success. Thanks much for any assistance. |
Quote:
Code:
~ $ cat <tester |
Here are 3 more possible solutions:
Code:
sed 's/\..*//' file # assuming that the dot is unique and always there |
All times are GMT -5. The time now is 05:09 PM. |