extract only filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers extract only filename
# 1  
Old 12-27-2007
extract only filename

Hi,

I want to display only the file names of the ls command with a delimiter of comma.

For example:-

ls /etc/dir/N*

gives the following output

/etc/dir/N1 /etc/dir/N2 /etc/dir/N3

I want the output as N1,N2,N3,-->Here i need the final comma also.

Also, here /etc/dir is being passed as a parameter and hence will be dynamic

Please let me know how we can implement this.

Thanks.
# 2  
Old 12-27-2007
Code:
# cd $dynamic_directory
# for i in N*; do printf "%s," $i; done
# cd ..

# 3  
Old 12-27-2007
Thanks a lot!!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract data before period in filename

Hi, I have some files with these patterns: WI_SCOPE_DATA_CHANGE_2017-09-12_15-30-40.txt WI_SCOPE_BACK_COMPLETE_QUEUE_2017-09-12_15-31-40.txt WI_SCOPE_CURRENT_CHECK_QUEUE_2017-09-12_15-32-40.txt WI_SCOPE_DAILY_PARTY_2017-09-12_15-33-40.txt I want to extract date from filename and save it... (1 Reply)
Discussion started by: Home
1 Replies

2. Shell Programming and Scripting

Extract the filename and write to .txt

I'm new to this forum and also to UNIX scripting. I need a command to extract the filename from the path and write to .txt file. Thanks in advance for your guidance. (23 Replies)
Discussion started by: Ram Kumar_BE
23 Replies

3. Shell Programming and Scripting

Extract filename from a given string

I want to extract the filename from a string. This is how I have the rawdata ina file /home/sid/ftp/testing/abc.txt /home/sid/ftp/tested/testing/def.txt /home/sid/sftp/date/misc/hij.txt i want a script which would provide me an output like this Directory ... (10 Replies)
Discussion started by: sidnow
10 Replies

4. UNIX for Dummies Questions & Answers

Extract Date part from the filename

Hi All, I have incoming source files abcmmyy.txt I need to extract the mmyy part from the filename and pass that to a variable . I really appreciate your quick response on this. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

5. Shell Programming and Scripting

Extract string from filename

Hi I need to extract the string from file name filename: FILENAME_STRUT_01032013_XXXXXXX.TXT I want 01032013 from the above file name. number of characters may differ before the required string but underscores(-) are same number i.e. after second underscore. Please advise on this. ... (2 Replies)
Discussion started by: cnrj
2 Replies

6. Shell Programming and Scripting

Extract a part of a filename containing a particular word

Hi All, Thanks in Advance Shell Script or Perl Script I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv... (7 Replies)
Discussion started by: aealexanderraj
7 Replies

7. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

8. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

9. Shell Programming and Scripting

loop and extract matching filename

i am unable to exact matching filename in the loop. Filename.in file contains Customer_Product_ Information_Customer_Product_ sale_Product_ /home_dir contains files CUST_INFO_990090_1111.csv "1","Customer Product Detail","1000","salary" "1","Information Customer Product... (2 Replies)
Discussion started by: onesuri
2 Replies

10. Shell Programming and Scripting

How to extract timestamp from the filename?

Hi., My file name is of the format: name_abc_20100531_142528.txt where., my timestamp is of the format: yyyymmdd_hhmmss How to extract the date strring and time string into seperate variables in the shell script, after reading the file as the input? I want to get the variables... (9 Replies)
Discussion started by: av_vinay
9 Replies
Login or Register to Ask a Question