[SOLVED] Moving of file content to another two files after searching with specific pattern
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Moving of file content to another two files after searching with specific pattern
Please help me with this!! Thanks in advance!!
I have a file named file.gc with the content:
1-- Mon Sep 10 08:53:09 CDT 2012
2revoke connect from FR2261;
3delete from mkt_allow where grantee = 'FR2261';
4grant connect to FR2261 with '******';
5alter user FR2261 comment
7grant CLNTSV_PEK to FR2261
9insert into mkt_allow
10select 'FR2261', marketkey
11from (select distinct marketkey
13where grantee in ('CLNTSV_PEK')
14) mktlist (marketkey)
-- Mon Sep 10 08:54:10 CDT 2012
revoke connect from NB2197;
delete from mkt_allow where grantee = 'NB2197';
grant connect to NB2197 with '*****';
alter user NB2197 comment
Kroger/Exxon/Mapco/LMP Stater Bros/Couch/petco';
grant CLNTSV_PEK to NB2197
insert into mkt_allow
select 'NB2197', marketkey
from (select distinct marketkey
where grantee in ('CLNTSV_PEK')
) mktlist (marketkey)
I need to search for the pattern FR2261 and need to move the lines from the pattern till the next semicolon ( to a file called revoke.
This revoke file already contains some date. I need to add the lines at the end of the revoke file.
Before adding this line i need to add one more line which looks like the output of
echo "--`date` Revoked as per $Requestor/$ticket" (where Requestor and ticket are two variables read from the user).
Also we need to paste the lines starting with revoke and delete (ex: lines 2&3) matched to the pattern FR2261 to a file called man_revoke. This revoke file already contains 4 lines (may also change). 1st line and last line should be as it is. Only in between lines need to be replaced with the current revoke&delete lines.
After copying those lines to revoke & man_revoke files i need to delete the same lines from file.gc file. Also we should remove the line -- Mon Sep 10 08:53:09 CDT 2012.
Sometimes this line may not exist. If it doesn't exist, we just neglect that part. so we need to give a condition as if the line prior to the searched pattern contains "--" (reference of the above line) we need to delete that line. Otherwise, we need to neglect it.
How the above steps can be performed for multiple patterns (like FR2261 &NB2197)
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
The tool you'll most likely want to use for most of this is sed.