Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thanks! Awesome group. I put out a simple question in the access/vba forum that I couldn't find answered on technet or anywhere else on the web and it was answered the same day!!..."

Geography

Where in the world do Tek-Tips members come from?
w5000 (TechnicalUser)
30 Mar 12 6:52
with slash (or multiple slashed) on the beginning of lines but also such slash(es) led and/or trailed by spaces/tabs and also lines with space in a direcotry name (usually typo)

Example of lines which should be rid off:

CODE

/
 /  dgf / dfg
   ////
///////
/sfsd/sfd /
/sfsd/sfdsfs /dfgf/df/
/dfgdg /gddd /

and which should NOT be removed

CODE

///sfsffs
/d/d/d/d
  /ssfsfsf

Multiple occurences of / (like in example ///sfsffs) could also be replaced by single / (/sfsffs)

I want to avoid "/" filesystem "representants" from the file.


 
blarneyme (MIS)
30 Mar 12 7:17

CODE

# touch ^Uadfasd  (created using ctrl-v ctrl-u)
# ls                                                    
adfasd
# rm adfasd
rm: adfasd: A file or directory in the path name does not exist.

# set -A arr $(ls .)
# echo ${arr[*]}
adfasd
# rm ${arr[*]}
# ls
#
w5000 (TechnicalUser)
30 Mar 12 7:35


ok, I think this will do the job:

CODE

sed "s/^[[:space:]]*//;s/[[:space:]]*$//" test_file|sed s/[[:space:]]*//g|sed s,///*,/,g|grep ^\/|grep -v ^\/$
Annihilannic (MIS)
30 Mar 12 7:38

CODE

sed 's#//*#/#g' inputfile | awk '{for (i=1;i<=NF;i++) { if ($i == "/") next } ; print }'

The sed compresses multiple slashes into one.  The awk part rejects lines with an isolated "/".  

Note that I have allowed "/dfgf/df/" because it is perfectly acceptable to terminate a directory name with a slash; in fact in many cases preferable because it explicitly specifies a directory rather than a file.

 

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Helpful Member!  PHV (MIS)
30 Mar 12 7:45
Annihilannic (MIS)
31 Mar 12 10:47
PHV, that wouldn't remove these two lines:

CODE

/sfsd/sfd /
/sfsd/sfdsfs /dfgf/df/
/dfgdg /gddd /

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

PHV (MIS)
31 Mar 12 13:15
PHV, that wouldn't remove these two lines
Really ?
awk 'NF==1&&$1!~"^/*$"' /path/to/input
Annihilannic (MIS)
31 Mar 12 20:22
True, true... okay, but it *would* remove a line with two valid directories, e.g. "/somepath /some/other/path".

I assume that is not what the OP wanted.

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Helpful Member!  PHV (MIS)
1 Apr 12 10:53
I assume that is not what the OP wanted
Reread the 1st post ...
Helpful Member!  Annihilannic (MIS)
1 Apr 12 11:38

Quote (w5000):

also lines with space in a direcotry name (usually typo)

Hmm... okay... I'll crawl back under my stone now.  smile

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close