Sponsored Content
Top Forums Shell Programming and Scripting Finding a match and deleting the line above to it.. Post 302743689 by raosr020 on Thursday 13th of December 2012 10:51:30 AM
Old 12-13-2012
Hi Pamu,

Thanks for the reply!!

But with that code any other revoke connect lines also getting deleted (ex: revoke connect from CALU is also getting deleted).

My original file:

Code:
Sun is Hot
Moon is cool
;

-- Mon Sep 10 08:54:10 CDT 2012
-- Mon Sep 11 08:54:10 CDT 2012
-- Mon Sep 12 08:54:10 CDT 2012
revoke connect from SREE;
delete from = 'SREE';
grant connect to SREE with 'fastcar8';
 
-- Mon Sep 12 08:54:10 CDT 2011
revoke connect from CALU;
delete from = 'CALU';
grant connect to CALU with 'calendar';

After running the below command:
Code:
awk '{if($0 ~ /^--/){A[++a]=$0}else if(a && $0 !~ /revoke connect from SREE/){for(i=1;i<=a;i++){print A[a]};a=0}else{print ;a=0}}' file

Output is as follows:
Code:
Sun is Hot
Moon is cool
;

revoke connect from SREE;
delete from = 'SREE';
grant connect to SREE with 'fastcar8';
 
-- Mon Sep 12 08:54:10 CDT 2011
delete from = 'CALU';
grant connect to CALU with 'calendar';

In above ouput
Code:
revoke connect from CALU;

line is missing. That shouldn't happen. Please correct the code.


And i cann't redirect this output to a temporary file. These changes should happen to the original file itself.

Please help me in getting these two requirements solved.

Thanks,
Sreenivas

---------- Post updated at 09:21 PM ---------- Previous update was at 06:50 PM ----------

Hi Scrutinizer

Thanks for the reply!!

Your code is not working. Please suggest me the solution based on the above requirement.

Thanks,
Sreenivas

Last edited by raosr020; 12-13-2012 at 11:46 AM.. Reason: changes made
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with finding certain files, and then deleting

I must really be bad at life today, because I couldn't even find a search option on the forums before asking for help, so I apologize if this is already listed somewhere. I'm pretty new to UNIX, and basically only know enough to be dangerous. I have been appointed a task to basically go to a... (2 Replies)
Discussion started by: Puck
2 Replies

2. Shell Programming and Scripting

Deleting / finding files older than X days missess a day

Hi When trying to find and delete files which are, say, 1 day, the find command misses a day. Please refer the following example. xxxd$ find . -type f -ctime +1 -exec ls -ltr {} \; total 64 -rw-rw-r-- 1 oracle xxxd 81 Apr 30 11:25 ./ful_cfg_tmp_20080429_7.dat -rw-rw-r-- 1... (4 Replies)
Discussion started by: guruparan18
4 Replies

3. Shell Programming and Scripting

Is there an efficient way in finding and deleting files?

Hi I have a script to find and delete the files which are say, noDaysOld, I am interested to find the number of such files I am fniding for deleting and then deleting it. So, the script I wrote, first finds the number of such files and then deletes, clearly this is two different steps. ... (3 Replies)
Discussion started by: guruparan18
3 Replies

4. Shell Programming and Scripting

Finding duplicate lines and deleting folders based on them

Hi, I have research data, which is organized to 100 folders numbered 00-99. I have many sets of 100 folders, for different values of initial parameters. For some reason, the computer that ran the program to gather the data, didn't always create a unique seed for each folder. I anticipated that... (1 Reply)
Discussion started by: Jopi
1 Replies

5. Shell Programming and Scripting

Finding a flatfile & deleting first line

I have a small script where I want to see if a file exists & then delete the first line from it. I have code to help me find if the file exists, but I am unsure as to how to then take in the answer and remove the first line from the flatfile: This is what I have so far just to output if the... (3 Replies)
Discussion started by: fatalxkiss
3 Replies

6. Shell Programming and Scripting

help with finding text and deleting line

HI All, I need to search for a particular pattern input by the user in order to delete the line. My username.txt has username@email.com:John:149.0.3.4:1 username1@email.com:Harry:149.0.3.4:1 username1@email.net:Alex:149.0.3.4:1 username1@email.edu:Nemo:149.0.3.4:1 The program i written ... (3 Replies)
Discussion started by: ichar
3 Replies

7. UNIX for Dummies Questions & Answers

Deleting files based on Substring match

In folder there are files (eg ABS_18APR2012_XYZ.csv DSE_17APR2012_ABE.csv) . My requirement is to delete all the files except today's timestamp I tried doing this to list all the files not having today's date timestamp #!/bin/ksh DATE=`date +"%d%h%Y"` DIR=/data/rfs/... (9 Replies)
Discussion started by: manushi88
9 Replies

8. UNIX for Dummies Questions & Answers

Deleting rows where the value in a specific column match

Hi, I have a tab delimited text file where I want to delete all rows that have the same string for column 1. How do I go about doing that? Thanks! Example Input: aa 1 aa 2 aa 3 bb 4 bc 5 bb 6 cd 8 Output: bc 5 cd 8 (4 Replies)
Discussion started by: evelibertine
4 Replies

9. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

10. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies
REVOKE(2)						      BSD System Calls Manual							 REVOKE(2)

NAME
revoke -- revoke file access LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> int revoke(const char *path); DESCRIPTION
The revoke() system call invalidates all current open file descriptors in the system for the file named by path. Subsequent operations on any such descriptors fail, with the exceptions that a read() from a character device file which has been revoked returns a count of zero (end of file), and a close() system call will succeed. If the file is a special file for a device which is open, the device close function is called as if all open references to the file had been closed. Access to a file may be revoked only by its owner or the super user. The revoke() system call is currently supported only for block and character special device files. It is normally used to prepare a terminal device for a new login session, preventing any access by a previ- ous user of the terminal. RETURN VALUES
The revoke() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
Access to the named file is revoked unless one of the following: [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an entire path name exceeded 1024 characters. [ENOENT] The named file or a component of the path name does not exist. [EACCES] Search permission is denied for a component of the path prefix. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EFAULT] The path argument points outside the process's allocated address space. [EINVAL] The implementation does not support the revoke() operation on the named file. [EPERM] The caller is neither the owner of the file nor the super user. SEE ALSO
close(2), revoke(1) HISTORY
The revoke() system call first appeared in 4.3BSD-Reno. BSD
June 4, 1993 BSD
All times are GMT -4. The time now is 06:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy