Shell Script to Delete part text of a line if pattern matches
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
From what i see, the code is reading the whole line and stripping off the data till the last '/' in the line.
I can put an exception using your solution, but then i need this code to be executed on approx 100 scripts which will have similar exceptions. It'll be very time consuming and cumbersome to find and accommodate all of them.
On the other side, I see this problem ONLY occurs when there is more than 1 command with absolute path in the SAME line.(in the above example '/usr/bin/cp' and '/tmp/$ALERT')
So how can we tune the code to consider the stripping to end when it finds a word between of last '/' of the string and 'space', and continue reading the remaining line for further seperate stripping.
I am not sure what exactly the problem is. If you cannot say what these exceptions look like and if there is no general pattern that all this exceptions have in common then I am afraid that your task cannot be achieved with a few lines of code. From your description so far I take it that in one script it is the line which contains 'CFG_DIR' that has to remain unchanged and in the next script this variable is named differently. You might have to create a more advanced script that can deal with the complexity of the task.