Sponsored Content
Top Forums Shell Programming and Scripting Need a script or one-liner to purge lines from a file. Post 302461894 by BRH on Tuesday 12th of October 2010 04:30:43 PM
Old 10-12-2010
Need a script or one-liner to purge lines from a file.

i all.

This one sounds so simple, but I can't get it to work. I need to delete lines with certain keywords from a file.

I have a file called defaultRules, with keywords:

Code:
IPSEC_AH
IKE_UDP
IPMP_TEST_IFACE2

Then, I have another file called rules.txt with some rules:

Code:
'344.','IPSEC_ESP','','','','','1.','0.','0.','0.','0.','5.','1.','Allow IPSec ESP Packets on all IP interfaces'
'345.','IPSEC_AH','','','','','1.','0.','0.','0.','0.','6.','1.','Allow IPSec AH Packets on all IP interfaces'
'346.','IKE_TCP','','','','','1.','500.','0.','0.','0.','3.','1.','Allow IKE Negotiation on all IP interfaces'
'347.','IKE_UDP','','','','','1.','500.','0.','0.','0.','2.','1.','Allow IKE Negotiation on all IP interfaces'
'348.','CLUSTER_IC_NODE1','clusternode1-priv','','','','1.','0.','0.','0.','0.','4.','1.','Allow cluster inter-connect packets from node 1'
'349.','CLUSTER_IC_NODE2','clusternode2-priv','','','','1.','0.','0.','0.','0.','4.','1.','Allow cluster inter-connect packets from node 2'
'350.','ICMP_NODE_IP','ipmp_node_alias','','','','1.','0.','0.','0.','0.','1.','1.','Allow ICMP to Node IP'
'351.','ICMP_BMS','ipmp_bms','','','','1.','0.','0.','0.','0.','1.','1.','Allow ICMP to BMS IP'
'352.','IPMP_TEST_IFACE1','ipmp_test_alias_1','','','','1.','0.','0.','0.','0.','1.','1.','Allow IPMP Test Packets on 1st test interface'
'353.','IPMP_TEST_IFACE2','ipmp_test_alias_2','','','','1.','0.','0.','0.','0.','1.','1.','Allow IPMP Test Packets on 2nd test interface'

The objective is to remove all lines in rules.txt that contain the keywords in defaultRules, so I tried this by first renaming the keywords to 'unused' and then removing all lines that contain 'unused':

Code:
for a in `cat defaultRules` ; do sed -e 's/$a/unused/' rules.txt | grep -v unused > rules.out ; done

It did nothing, rules.txt and rules.out are identical. Smilie

Any ideas?

Thanks in advance,
BRH
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script for purge

Hi , I want to purge 7 days older data from a list of data sorted on date in a log file... Can anyone provide me with the shell script for the same.. Thanks, Jaz (1 Reply)
Discussion started by: JP003
1 Replies

2. Shell Programming and Scripting

shell script for archive purge

I am writing a shell script for Archive Purge for the table having rows < 1 year. The shell script has to extract the rows from the table and write those extracted rows to a text file. Then from the text file, each rows will be read and deleted by means of delete query one by one. The fields will... (5 Replies)
Discussion started by: regnumber
5 Replies

3. Shell Programming and Scripting

script to archive and purge

Hi, I am writing a shell script for archive data from a table. The design is as follows. Step 1: Execute the select query and extract the data into a text file. Step 2: The primary key for this table is TRACKING_NUM, TRACKING_NUM_SUFFIX, TIMESTAMP_UPDATED. So These three fields will be read... (1 Reply)
Discussion started by: kmanivan82
1 Replies

4. Shell Programming and Scripting

Sed one-liner to print specific lines?

I need to print specific lines from a file, say 2-5, 8, 12-15, 17, 19, 21-27. How do I achieve this? (2 Replies)
Discussion started by: Ilja
2 Replies

5. Shell Programming and Scripting

Shell script to check the files hourly and purge

I'm new to shell scripting... i have been given a task.. can any one help in this regard.... 1) Check hourly for files in <destination-path><destination-file-template><destination-file-suffix> for files older than <destination-file-retention> days and purge. It should then check... (1 Reply)
Discussion started by: satishpabba
1 Replies

6. UNIX for Advanced & Expert Users

Purge MAil file

Hi, merry christmas. on AIX 6.1, the file /var/spool/mail/user, should/can be purged manually ? Any commande line to purge it ? Thanks. (2 Replies)
Discussion started by: big123456
2 Replies

7. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

8. Shell Programming and Scripting

To create a script and schedule which purge 30 days old files

Hi Friends, Very new in Unix and i got a requirement like writing a script and schedule it, so that it removes 30 days old files from all the log locations of a unix box. Suppose i have a unix server ltbamdev1 and in this server i have a mount point opt/bam. In this mount point i have 3... (1 Reply)
Discussion started by: duos
1 Replies

9. Shell Programming and Scripting

Perl one liner to wrap comment lines

Greetings fellow scripters. I find myself editing multiple files, sometimes with the same bits of information. My bash script, a changelog, and a plist file (OS X). Once I realized this, I thought why not script part of this process (and so it begins). In any case, I've solved several of the... (1 Reply)
Discussion started by: reid
1 Replies

10. Shell Programming and Scripting

sed one liner to Delete blank lines - Help required

Hi, cat test.txt BlankLine BlankLine BlankLine BlankLine ello hi helo BlankLine BlankLine heylo BlankLine BlankLine BlankLine done BlankLine BlankLine BlankLine (1 Reply)
Discussion started by: TomG
1 Replies
vxusertemplate(1M)														vxusertemplate(1M)

NAME
vxusertemplate - create and administer user templates SYNOPSIS
vxusertemplate -d file [-f] create [template [template ...]] vxusertemplate [-f] create template_name [description=description] [rules=rules] [capability=capability(var=value,...)[,capability...]] vxusertemplate delete template vxusertemplate help [keywords | options | attributes] vxusertemplate list vxusertemplate print template [template ... ] DESCRIPTION
The vxusertemplate utility provides a command line interface for the creation and administration of user-defined or user templates that may be used with the Veritas Intelligent Storage Provisioning (ISP) feature of Veritas Volume Manager (VxVM). The operations that can be performed by vxusertemplate are selected by specifying the appropriate keyword on the command line. See the KEY- WORDS section for a description of the available operations. KEYWORDS
create Creates one or more user templates, whose definitions can be read from a definitions file or entered on the command line. delete Deletes a user template. help Displays information on usage, keywords, options and attributes. list Lists all user templates. print Prints detailed information about one or more user templates. OPTIONS
-d file Specifies a file that contains user template definitions -f Forces an operation that is not usually allowed by vxusertemplate. This option must be specified if the user template definition differs from the existing definition in the configuration database. EXAMPLES
Create the user templates ut1, ut2 and ut3 from the definitions in the file ut1.txt: vxusertemplate -d ut1.txt create ut1,ut2,ut3 Delete the user template myreliabletemplate: vxusertemplate delete myreliabletemplate List all user templates: vxusertemplate list Print details of the user template mytemplate: vxusertemplate print mytemplate EXIT STATUS
The vxusertemplate utility exits with a non-zero status if the attempted operation fails. A non-zero exit code is not a complete indicator of the problems encountered, but rather denotes the first condition that prevented further execution of the utility. SEE ALSO
vxtemplate(1M), vxvoladm(1M) Veritas Storage Foundation Intelligent Storage Provisioning Administrator's Guide VxVM 5.0.31.1 24 Mar 2008 vxusertemplate(1M)
All times are GMT -4. The time now is 08:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy