Moving of file content to another two files after searching with specific pattern

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Moving of file content to another two files after searching with specific pattern
# 1  
Old 12-04-2012
Computer Moving of file content to another two files after searching with specific pattern

Hello,
Please help me with this!! Thanks in advance!!
I have a file named file.gc with the content:
Code:
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
6Channel/SP/LMP';
7grant CLNTSV_PEK to FR2261
8;
9insert into mkt_allow
10select 'FR2261', marketkey
11from (select distinct marketkey
12from mkt_allow
13where grantee in ('CLNTSV_PEK')
14) mktlist (marketkey)
15;
-- 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
from mkt_allow
where grantee in ('CLNTSV_PEK')
) mktlist (marketkey)
;

Query1:
I need to search for the pattern FR2261 and need to move the lines from the pattern till the next semicolon (Smilie 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).
Query:
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.
Query3:
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.
Query4:
How the above steps can be performed for multiple patterns (like FR2261 &NB2197)

Best Regards,
Sreenivas

Last edited by Scott; 12-04-2012 at 06:06 AM.. Reason: Please use code tags, and less formatting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux read specific content file from tar.gz files without extracting

hello i wish to write the result of these below conditions in a file: 1. in a specific folder, i have many tar.gz files. 2. each tar.gz file contains ".dat" file in sub folders. 3. i wish to get the full path of these .dat files, if i find in it a specific word ("ERROR24"). 4. all this... (6 Replies)
Discussion started by: jimmyjames9
6 Replies

2. Shell Programming and Scripting

How to remove content present in between specific pattern ?

Hi, I have a file with following pattern. We are looking to filter out only specific content from this file. sample BLAdmins Server.* LinuxAdmins Server.* Policy Name: Recommended Default ACL Policy Everyone ACLPushJob.Read Everyone ACLTemplate.Read Everyone ... (9 Replies)
Discussion started by: Litu19
9 Replies

3. Shell Programming and Scripting

Finding 4 current files having specific File Name pattern

Hi All, I am trying to find 4 latest files inside one folder having following File Name pattern and store them into 4 different variables and then use for processing in my shell script. File name is fixed length. 1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number... (6 Replies)
Discussion started by: lancesunny
6 Replies

4. Shell Programming and Scripting

Help with replace the content of specific pattern

Input file: __<name>AWEETET</name> ____<name_evidence="3"_type="2@#">QEWQE</name> __<name>QWE048</name> ____<name_evidence="3"_type="570">@#@$#545</name> ____<name_evidence="2"_type="351">QWE4</name> Desired output: __<tmp>AWEETET</tmp> ____<name_evidence="3"_type="2@#">QEWQE</name>... (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Regarding multiline record searching with specific pattern

Dear Experts, I need to extract specific records from one file which has multiline records. Input file pattern is: ============ aaaaaaaa bbbbbbbb asdf 1234 cccccccc dddddddd ============ aaaaaaaa bbbbbbbb qwer 2345 cccccccc dddddddd (7 Replies)
Discussion started by: dhiraj4mann
7 Replies

6. Shell Programming and Scripting

awk/sed/perl command to delete specific pattern and content above it...

Hi, Below is my input file: Data: 1 Length: 20 Got result. Data: 2 Length: 30 No result. Data: 3 Length: 20 (7 Replies)
Discussion started by: edge_diners
7 Replies

7. Shell Programming and Scripting

Remove specific pattern header and its content problem facing

Input file: >TRACK: Position: 1 TYPE: 1 Pos: SVAVPQRHHPGGTVFREPIIIPAIPRLVPGWNKPIIIGRHAFGDQYRATDRVIPGPGKLE LVYTPVNGEPETVKVYDFQGGGIAQTQYNTDESIRGFAHASFQMALLKGLPLYMSTKNTI LKRYDGRFKDIFQEIYESTYQKDFEAKNLWYEHRLIDDMVAQMIKSEGGFVMALKNYDGD >TRACK: Position: 1 TYPE: 2 Pos: FAHASFQMALLKGLPLYMS... (8 Replies)
Discussion started by: patrick87
8 Replies

8. Shell Programming and Scripting

Help needed with searching files and moving them to a different directory

I am new to shell scripting. Can someone help me out with this one please? I need to write a script fot the following scenario: I am currently in /parent directory. I have a set of files in /parent/error_files directory My script has to search for a file in /parent/erratic_files... (1 Reply)
Discussion started by: ss3944
1 Replies

9. Shell Programming and Scripting

searching content of files in the current and sub directories

Hi I was wondering why command 2 doesn't work like command 1 below. 1. find . -exec grep "test" '{}' \; -print 2. ls -R | grep "test" I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2? Thanks in advance for your help (4 Replies)
Discussion started by: tiger99
4 Replies

10. UNIX for Dummies Questions & Answers

searching for content of files

Hi, This question may be quite newbish. I've stored a few files on my Unix system and am wondering how to search for their contents (i.e. I input the keyword and get a list of files with this keyword) I'd then like to put it on my website (php). I thought of find and grep, but am not... (19 Replies)
Discussion started by: Aretai
19 Replies
Login or Register to Ask a Question