finding files in Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding files in Unix
# 1  
Old 12-20-2005
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
# 2  
Old 12-20-2005
For your first question: find . -name "*.ph" -o -name "*.h"
# 3  
Old 12-20-2005
As I understand, you want to change a file name from within vi.

Code:
:!mv 001123456 001-123-456

# 4  
Old 12-20-2005
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
# 5  
Old 12-21-2005
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
# 6  
Old 12-21-2005
Hi RTM

Your code works like charm thank you

regards
Hrishy
# 7  
Old 12-22-2005
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 Smilie, 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 Smilie
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding total distinct count from multiple csv files through UNIX script

Hi All , I have multiple pipe delimited csv files are present in a directory.I need to find out distinct count on a column on those files and need the total distinct count on all files. We can't merge all the files here as file size are huge in millions.I have tried in below way for each... (9 Replies)
Discussion started by: STCET22
9 Replies

2. Shell Programming and Scripting

Finding out the common lines in two files using 4 fields with the help of awk and UNIX

Dear All, I have 2 files. If field 1, 2, 4 and 5 matches in both file1 and file2, I want to print the whole line of file1 and file2 one after another in my output file. File1: sc2/80 20 . A T 86 F=5;U=4 sc2/60 55 . G T ... (1 Reply)
Discussion started by: NamS
1 Replies

3. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

4. UNIX for Dummies Questions & Answers

finding files in unix and excluding certain folders

hi good day I am using redhat linux. Is there a better utility than the 'find' command to search for files I am trying to search through and enitre directory such as /repos for a files that have 'UAP' in it. However there are some '.step' folders littered throughout the /repos folder at varying... (8 Replies)
Discussion started by: johnstrong
8 Replies

5. Shell Programming and Scripting

Finding just unix user

I need to check for username that we are logged in.There are a lot of unix users and proceed according to that i.e find unix user if then echo "x" elif then echo "y' fi fi Now I dont know how to find and put user in if condition (8 Replies)
Discussion started by: sriki32
8 Replies

6. Shell Programming and Scripting

a comand finding all files from unix system

Hi, I am new in using unix systems and I need your help. I would like to make a command that prints all files (not directories) from a file system. These files must be executable from all users (--x --x --x) Thank you in advance (2 Replies)
Discussion started by: peter20
2 Replies

7. Shell Programming and Scripting

Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using if ;then echo "exists" echo " `cat $file` " else echo "invalid file" fi. and i can find out using : find / -name "filename" . But it i have wanted to search in all directories. How to get... (3 Replies)
Discussion started by: rparsa001
3 Replies

8. UNIX for Dummies Questions & Answers

Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories. Please suggest any ideas (10 Replies)
Discussion started by: abhilashnair
10 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

10. UNIX for Dummies Questions & Answers

Finding files in Unix

I need help with the syntax to serach a directory and all the folders in that directorys for a single pdf file. I would than like to move that file to another folder. I don't know if this is possible with one command. Please Help. (2 Replies)
Discussion started by: johnlong
2 Replies
Login or Register to Ask a Question