finding files in Unix

Hi

1)How do i find files in unix that end either in .pc or .h

This does not return any output

find . -name "*(pc|h)"

2)I have a file like this
001123456
..

...

i want the output to be like
001-123-456 any tricks in regular expression can do this in vi.

regards
Hrishy

For your first question: find . -name ".ph" -o -name ".h"

As I understand, you want to change a file name from within vi.

:!mv 001123456 001-123-456

i interpret the second question as, the content of the file is 001123456 and you want to change this to 001-123-456 on each line ?
if this is the case and you are using vim, then you can record a macro for one line and then play it for rest of the lines. If you are using simple vi the following command may help you
:s/\(...\)\(...\)\(...\)/\1-\2-\3/g

Hi Linuxpenguin

Your understanding is correct.

But your answer has my head twirl what on the earth is that supposed to mean :-).Can you please dissect it for me.

regards
Hrishy

Hi RTM

Your code works like charm thank you

regards
Hrishy

Hi Hrishi,
ok, if you happen to read man page for sed or ed, you will get what it means. But I will go ahead to tell you what this one specifically means
:s ( search and replace)
/ pattern separator (you may use # or ? or some other characters as well, must / is most generic
\esacpe seq for (, where ( marks opening of block pattern ( i m not sure bt the term).
The . means any character, so ... means any 3 characters. so i make 3 blocks, with 3 characters each. they are autmatically marked as 1 2 and 3.
then the second / terminates the pattern to search for. so you have asked so far to search a pattern that has 9 characters, and you have grouped them in 3 groups of 3 characters each. Now you start to replace them, with what ? right, with each of the group separated by a -. so first group is \1, second is \2 third is \3. you can have upto 9 such grouped patterns (here i got the term :), it is called grouped patterns).
and then the last /g, means globally
so search a pattern of 9 characters, grouping them in groups of 3 of 3 characters each and replace them globally by the same grouped patterns separated by hyphen :slight_smile:
having said that, if you had more than 9 characters on the line, the rest would be neglected till there were 18, if you had 18, you wud have 6 groups, and so on. try playing with that and read some man page for sed. There is immense pattern help with sed.

Hi LinuxPenguin

Thank you very very much..dude you are awesome.

regards
Hrishy