Help! I sux @ Unix

For system help, all hardware / software topics NOTE: use Coders Corner for all coders topics.

Moderators: Krom, Grendel

Post Reply
User avatar
Nitrofox125
DBB Admiral
DBB Admiral
Posts: 1848
Joined: Sun Jul 07, 2002 2:01 am
Location: Colorado Springs, CO, USA
Contact:

Help! I sux @ Unix

Post by Nitrofox125 »

Well actually I have a few different questions here.

1. How do I use wildcards in a delete? I have lines like this say:
VALUES('-1','2','Whee','OMG');
And I want them to end up like this:
VALUES('2','Whee','OMG');
With the -1 gone. However I can't just do a normal find and replace, because the -1 changes with every line. what program can do this and what is the command/way to do this?
The closest i got was in VI
:s/VALUES('*',/VALUES(/g but that didn't work.

2. How to list only directories in unix ls?
What I'm looking for is the unix equivilent to
dir /s /ad /s *

Thanks
:D
User avatar
Instig8
DBB Ace
DBB Ace
Posts: 347
Joined: Wed Jun 20, 2001 2:01 am
Location: Orange County, CA, USA
Contact:

Post by Instig8 »

study up on your regular expressions.

and, for god's sake, read the man or info pages.

i don't know much about vi. maybe try

Code: Select all

:s/VALUES('[*]',/VALUES(/g
and, i always use

Code: Select all

ls -lap
(aliased to l) to list directories.
User avatar
Nitrofox125
DBB Admiral
DBB Admiral
Posts: 1848
Joined: Sun Jul 07, 2002 2:01 am
Location: Colorado Springs, CO, USA
Contact:

Post by Nitrofox125 »

I looked at the man pages for ls and it didn't really give me what I wanted... :
Thanks for that other info though...

I was thinkin maybe like :s/VALUES('[0-9]',/...... or something might work..
R e v
DBB Admiral
DBB Admiral
Posts: 1121
Joined: Wed Mar 24, 1999 3:01 am

Re: Help! I sux @ Unix

Post by R e v »

Nitrofox125 wrote:2. How to list only directories in unix ls?
'ls' does not support listing only directories.

To show all directories try the following:
find -type d -maxdepth 1

If you are new to *nix, or anything for that matter, www.google.com is your friend.
User avatar
Admiral LSD
DBB Admiral
DBB Admiral
Posts: 1240
Joined: Sun Nov 18, 2001 3:01 am
Location: Northam, W.A., Australia
Contact:

Post by Admiral LSD »

sed I think might be capable of doing what you want. You'll have to read up on the syntax though as I don't know it off the top of my head.
Cuda68-2
DBB Ace
DBB Ace
Posts: 320
Joined: Fri Sep 20, 2002 2:01 am
Location: St. Paul Minnesota
Contact:

Post by Cuda68-2 »

http://unix.about.com/library/glossary/ ... tution.htm

It also has the valid wildcard characters defined for *nix.
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy »

This finds all directories below this one:

find . -type d

If you want to make this command available in a short form (for example, if you want to be able to call "lsdir" and get this result) put the following line in a file called .bashrc in your home (~) directory.

alias lsdir='find . -type d'
User avatar
Instig8
DBB Ace
DBB Ace
Posts: 347
Joined: Wed Jun 20, 2001 2:01 am
Location: Orange County, CA, USA
Contact:

Post by Instig8 »

If you don't want subs, maybe use:

alias lsdir='ls -lp |grep /'

Now, when you type lsdir you only see directories. A million ways to skin a cat.
User avatar
Nitrofox125
DBB Admiral
DBB Admiral
Posts: 1848
Joined: Sun Jul 07, 2002 2:01 am
Location: Colorado Springs, CO, USA
Contact:

Post by Nitrofox125 »

Lol... find . -type d -maxdepth 1 worked quite well. Thanks all!
R e v
DBB Admiral
DBB Admiral
Posts: 1121
Joined: Wed Mar 24, 1999 3:01 am

Post by R e v »

Nitrofox125 wrote:Lol... find . -type d -maxdepth 1 worked quite well. Thanks all!
you're welcome
Post Reply