Capture filenames with a Pattern into another file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Capture filenames with a Pattern into another file
# 1  
Old 09-28-2011
Capture filenames with a Pattern into another file

Hi i have a command in windows which captures the filenames with the same pattern and route it to another file.

for example filetest_20110921, filetest_20110922,filetest_20110923 etc

I would like to know the command in UNIX/LINUX for the same. The command which i am using in Windows is

cmd \c dir <dir>\filetest*.txt /b /a:-d > <dir>\All_File_Names.txt

Please let me know what can be the equivalent command in UNIX.

Thanks,
Mansur
# 2  
Old 09-28-2011
Code:
ls filetest*.txt > All_File_Names.txt

# 3  
Old 09-28-2011
Could you please let me know how to mention the directories?
# 4  
Old 09-28-2011
Code:
ls filetest*.txt /any_dir/anyfile*.any_extension /some/other/random/txt/file*.txt > All_File_Names.txt

# 5  
Old 09-28-2011
ls filetest*.txt /any_dir/anyfile*.any_extension /some/other/random/txt/file*.txt > All_File_Names.txt
-------------
Is the following command is true?
ls filetest*.txt/incoming/filetest*.txt/ > All_File_Names.txt
# 6  
Old 09-28-2011
Quote:
Originally Posted by mansurkhalil
ls filetest*.txt/incoming/filetest*.txt/ > All_File_Names.txt
Imagine you were typing "del *.txt *.pdf" into CMD, then stripped out the space, what would "del *.txt*.pdf" do in CMD? It'd complain "no such file or directory" because there's no file matching *.txt*.pdf. By stripping out the spaces you're mushing everything together into one big expression. The same happens when you do that in shell.

UNIX shell is very different from windows CMD in that it handles * for you. In CMD, if you do echo *.txt it prints *.txt. In shell, when you do echo *.txt it fills in *.txt with every matching filename!

'ls' isn't necessary for *, wildcards work with any command in shell. ls is just used here to make it print them one per line instead of all on one line.
# 7  
Old 09-28-2011
I still did not understand whether the command which was given is correct or not?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pattern Match FileNames

I am on AIX. I need to list the contents of the directory based on a pattern and write an XML output file with file names. If a filename does NOT match the below pattern then write an OUTPUT xml file in the below xml format Pattern Starts with (.abc) and contains (def) Starts with... (4 Replies)
Discussion started by: techedipro
4 Replies

2. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

3. UNIX for Dummies Questions & Answers

Distinct filenames pattern

Hi All, I am working on designing the archival process for my system, where I will have to find distinct file names ( when excluded time_stamp extention ) from given directory and for each file type keep the latest and move all other older to different location ( lets say dir Back ). Below are... (2 Replies)
Discussion started by: freakabhi
2 Replies

4. Shell Programming and Scripting

How to capture a string enclose by a pattern within a file?

Hi all, My file :test.txt just like this: ........................... From: 333:123<sip:88888888888@bbbb.com To: <sip:123456@aaaaa.com ......................... I want a script to capture the string between sip: & @ Expect output: 88888888888 123456 Please help! (4 Replies)
Discussion started by: Alex Li
4 Replies

5. UNIX for Dummies Questions & Answers

Searching for a pattern from filenames stored in a file

Hi, I have got some 10 filenames stored in a file or displayed in the console as a result of some query i made.. Now I need to open each of these files and search for a pattern in these 10 files.. Can someone help me with this? Thanks, Jean (9 Replies)
Discussion started by: jeanjkj
9 Replies

6. Shell Programming and Scripting

Copying filenames into a new file

I have about 35,000 files in one directory. Here I have to write a ksh to take only the filenames of 500 files at a time and put them into a new file. Can anyone please help me. Thank you. (8 Replies)
Discussion started by: vpv0002
8 Replies

7. Shell Programming and Scripting

BASH find filenames in list that match certain "pattern."

I guess by "pattern," I mean something different from how that word is defined in the Linux world. If you take $ to mean a letter (a-z) and # to mean a number (0-9), then the pattern I'm trying to match is as follows: $$$##-####-###-###.jpg I'd like to write a script that reads in a list of files... (4 Replies)
Discussion started by: SilversleevesX
4 Replies

8. Programming

Sort the filenames containing . in file name

Hi All, I have a list of files in a directory ..which are look like: 42420031.1000 42420031.1001 42420031.396 42420031.402 42420031.403 42420031.404 42420031.405 42420031.406 42420031.407 42420031.408 42420031.409 Here when i do ls 42420031* |sort it gives the output as ... (3 Replies)
Discussion started by: sanj_eck
3 Replies

9. Shell Programming and Scripting

capture output of file and send last string thereof to new file

Hello, If I run a program from within shell, the output is displayed in the command line terminal. Is there a way I can capture that output and choose only the very last string in it to send it to a new file? Thank you (6 Replies)
Discussion started by: Lorna
6 Replies

10. UNIX for Advanced & Expert Users

pattern match in each line and capture it question

I need a clarification on one of the scripts that i have written, I new to file handling and i need help: I am trying to find a particular pattern in a file "****** PBX" in set of 5 files named: xy.cc3 xv.cc3 xx.cc3 xr.cc3 xd.cc3 in a directory. If i find the files starting with these... (16 Replies)
Discussion started by: bsandeep_80
16 Replies
Login or Register to Ask a Question