Need a script or one-liner to purge lines from a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a script or one-liner to purge lines from a file.
# 8  
Old 10-12-2010
how about this?

A bit convoluted but it works on my system:

Code:
tr '\n' '|' < rules.dat | sed 's/|$//' | xargs -iRULE egrep -v RULE data.dat

1) Change newlines to pipes
2) Remove trailing pipe
3) Pass concatenated rule as expression to grep -v
# 9  
Old 10-12-2010
Code:
awk 'FNR==NR{a[$0]; next} {for (i in a) if (index($0,i)) next; print}' defaultRules rules.txt

Regards,
Alister
# 10  
Old 10-12-2010
Quote:
Originally Posted by BRH
HI dan, no luck with this one either, it didn't complain, but it did nothing.
Hmm, do you have /usr/xpg4/bin/grep ?
Base on /usr/xpg4/bin/grep manual the solution should work as expected

Quote:
-f pattern_file

Reads one or more patterns from the file named by the path name pattern_file. Patterns in pattern_file are terminated by a NEWLINE character. A null pattern can be specified by an empty line in pattern_file. Unless the -E or -F option is also specified, each pattern is treated as a basic regular expression.
# 11  
Old 10-12-2010
Quote:
Originally Posted by ctsgnb
is there one in /usr/ucb/grep ? or give a try with egrep ?
Thanks for your reply, but nope and nope.

Regards,
BRH

---------- Post updated at 05:05 PM ---------- Previous update was at 04:52 PM ----------

Quote:
Originally Posted by danmero
Hmm, do you have /usr/xpg4/bin/grep ?
Base on /usr/xpg4/bin/grep manual the solution should work as expected
Hi Dan.
My mistake, /usr/xpg4/bin/grep did work. I changed user and hit the wrong directory.

Regards,
BRH

---------- Post updated at 05:06 PM ---------- Previous update was at 05:05 PM ----------

Thanks for everyone who replied, much appreciated.

Regards,
BRH
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question