1846628 Members
2158 Online
110256 Solutions
New Discussion

Re: command help

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

command help

I have a file that looks like this:

BobMenefee

I want it to look like this:

Bob Menefee
_____________________________________________
My input file is called caps
I enter the following command:

sed s/'[A-Z]'/' [a-z]'/g caps

and I get
[a-z]ob [a-z]enefee

Any ideas how to do this ?
UNIX IS GOOD
11 REPLIES 11
Martin Johnson
Honored Contributor

Re: command help

It is not a good idea to have spaces (or tabs) in you file names. Spaces/tabs have special meaning in the unix shells. You will have all sorts of problems trying to access the file.

HTH
Marty
Nobody's Hero
Valued Contributor

Re: command help

file name is called 'caps'

the data in the file is 'BobMenefee'

I want to use sed to change it to Bob Menefee.
UNIX IS GOOD
Tom Maloy
Respected Contributor
Solution

Re: command help

To put a blank before EVERY capital letter:

sed -e "s/\([A-Z]\)/ &/g" caps

Tom

Carpe diem!
Martin Johnson
Honored Contributor

Re: command help

Sorry, I misinterpreted your post:

"I have a file that looks like this:

BobMenefee

I want it to look like this:

Bob Menefee "

Marty
Nobody's Hero
Valued Contributor

Re: command help

Tom,

Thanks,

I've only been trying this for about 2 hours. It took you 2 seconds. I hate people like you.......just kidding.

Thanks a heck of a lot.

Bob
UNIX IS GOOD
A. Clay Stephenson
Acclaimed Contributor

Re: command help

I suggest that you takes Tom's solution and then pipe it through another sed to get rid of the leading space.

sed -e 's/\([A-Z]\)/ &/g' caps | sed -e 's/^ //'

If it ain't broke, I can fix that.
MANOJ SRIVASTAVA
Honored Contributor

Re: command help

Hi

I thibk you cannot subsitute for the whole set it slef bcoz the logic will fail when it seraches for what to put ?

may be you can try for each and then run the whole 26 times like this

sed s/'A'/a/g
sed s/'B'/b/g
sed s/'C'/c/g
and so on
and then run this on the cpas file



Manoj Srivastava
MANOJ SRIVASTAVA
Honored Contributor

Re: command help

Yep me too , mis read the post


Manoj Srivastava
Tom Maloy
Respected Contributor

Re: command help

perl solution, do not add blanks if a blank is already there:

perl -n -e '{s/([^ ])([A-Z])/$1 $2/;print}' caps
Carpe diem!
Tom Maloy
Respected Contributor

Re: command help

forgot the global flag...

perl -n -e '{s/([^ ])([A-Z])/$1 $2/g;print}' caps

need more caffeine...
Carpe diem!
H.Merijn Brand (procura
Honored Contributor

Re: command help

Only add a space before a capital that currently has a lower case letter in front:

# perl -pi -e 's/([a-z])([A-Z])/$1 $2/g' data_file
Enjoy, Have FUN! H.Merijn