The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
bash ps; remove the header, sort and reinsert gekeha Shell Programming and Scripting 3 07-21-2009 02:01 PM
bash while read how to remove \n character papasj Shell Programming and Scripting 3 05-25-2009 09:24 PM
[BASH] Remove Link from Filename Syekiya Shell Programming and Scripting 6 04-20-2009 11:12 AM
Remove html tags with bash dejavu88 Shell Programming and Scripting 4 05-22-2008 01:58 PM
bash find and remove text Movomito Shell Programming and Scripting 5 04-05-2008 01:48 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
Selective remove awk-bash

Hi

I have a folder that contain up to 1000 subfolder. Genereally i need just 2 or 3 of them and i can know apriori the name of the subfolder i want to keep.
I'd like to erase all the unnecessary subfolders.

I've tried with:

Code:
ls -l | awk '$8 !~ /name_fold/{print "rm -r " $8}'| sh
and it works becouse i keep the name_fold1 ...but just for 1 folder, I'd like to do something like:

Code:
ls -l | awk '$8 !~ /name_fold1 || name_fold2 /{print "rm -r " $8}'| sh
in order to erase almost all and kepp the name_fold1 and name_fold2

Any idea?

thanks

D
  #2 (permalink)  
Old 10-02-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
Something like this?

Code:
ls -l | awk '$8 !~ /name_fold1/ && $8 !~ /name_fold2/{print "rm -r " $8}'| sh
  #3 (permalink)  
Old 10-02-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Shorter
Code:
ls -l | awk '$8 !~ /name_fold[12]/{print "rm -r " $8}'| sh
  #4 (permalink)  
Old 10-02-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
that's great!

thanks both
  #5 (permalink)  
Old 10-02-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Some shells support extended globbing:

ksh

Code:
rm -r -- !(name_fold[12])
bash

Code:
shopt -s extglob
rm -r -- !(name_fold[12])
zsh (setopt extendedglob if not enabled):

Code:
rm -r -- ^name_fold[12]
Reply

Bookmarks

Tags
awk, bash

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0