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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
04-22-2015, 10:02 AM
#1
LQ Newbie
Registered: Apr 2015
Posts: 1
Rep:
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
04-23-2015, 08:22 AM
#2
Member
Registered: Nov 2013
Posts: 205
Rep:
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.
04-23-2015, 09:22 AM
#3
Senior Member
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881
Quote:
Originally Posted by
sudowtf
... 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
04-24-2015, 09:09 AM
#4
Senior Member
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881
Quote:
Originally Posted by
Siggloo
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
All times are GMT -5. The time now is 08:40 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News