LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2015, 10:02 AM   #1
Siggloo
LQ Newbie
 
Registered: Apr 2015
Posts: 1

Rep: Reputation: Disabled
Delete rows accoring to pattern in a file.


Hi

I have to create a document containing all permissons on a fileserver and then clean it from all inharited permissions and so on.

I have created the file with sudo ls -Rlae > FILE (file created about 800MB, almost 800 000 lines)

The pattern we want to search for is on five lines:

0: user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
1: group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
2: user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
3: group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
4: user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity

We want those five lines and the line before to be deleted.


So is there possible to make a awk-script to do this?
Or is it a better way to list permissions and create the file?

Regards
 
Old 04-23-2015, 08:22 AM   #2
sudowtf
Member
 
Registered: Nov 2013
Posts: 205

Rep: Reputation: 46
So is the keyword "inherited" the unique factor? If so how about
Code:
grep -v -B 1 "inherited" input.txt > output.txt
where -v is inverse, and -B 1 is include 1 line before

my system does not allow the -e parameter on ls for me to analyze.
 
Old 04-23-2015, 09:22 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by sudowtf View Post
... how about
Code:
grep -v -B 1 "inherited" input.txt > output.txt
where -v is inverse, and -B 1 is include 1 line before ...
This might not work. See my recently thread at http://www.linuxquestions.org/questi...xt-4175540507/

Daniel B. Martin
 
Old 04-24-2015, 09:09 AM   #4
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by Siggloo View Post
The pattern we want to search for is on five lines:

0: user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
1: group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
2: user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
3: group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
4: user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity

We want those five lines and the line before to be deleted.
Take those five lines and put them in a file called PatFile ...
Code:
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
I constructed a test InFile by making five copies of the pattern, planting a few "filler" lines between each, and then "munging" three of the five with 9's so that only two perfect matches remain.
InFile ...
Code:
Apple pie
Cherry cobbler
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:999999999 inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Vanilla ice cream
Chocolate ice cream
Strawberry ice cream
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Potatos
Broccoli
Asparagus
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,999999999999
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Ford
Honda
Toyota
Nissan
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Bicycle
Skateboard
Scooter
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_999999999 inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
The desired transformation is to "blow away" the two perfect matches, along with the filler line which immediately precedes them: strawberry ice cream, and Nissan.

This code ...
Code:
Pat="~"$(paste -sd"~" $PatFile)
 paste -sd"~" $InFile  \
|sed "s/$Pat/QQQ/g"    \
|tr "~" "\n"           \
|grep -v "QQQ"         \
>$OutFile
... produced this OutFile ...
Code:
Apple pie
Cherry cobbler
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:999999999 inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Vanilla ice cream
Chocolate ice cream
Potatos
Broccoli
Asparagus
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,999999999999
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Ford
Honda
Toyota
Bicycle
Skateboard
Scooter
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_spotlight inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
group:konceptit inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
user:_999999999 inherited allow read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Daniel B. Martin
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell script to delete a pattern from file deepmala8 Linux - Newbie 7 09-29-2011 11:28 PM
[SOLVED] how do you delete unwanted rows from a file? ameylimaye Linux - Newbie 7 09-28-2011 06:40 AM
sed: delete lines after last occurrence of a pattern in a file zugvogel Programming 4 11-17-2009 01:49 AM
Text file manipulation: Extracting specific rows according to numerical pattern CHARL0TTE Linux - Newbie 3 10-07-2009 07:14 AM
How to delete the file using pattern match? nishanthhampali Programming 3 04-16-2008 12:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration