Find files where filename ends with space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find files where filename ends with space
# 1  
Old 12-14-2016
Find files where filename ends with space

Hello all,

I would like to find files where the filename ends with a space - like Test.dat

I tried it with:

Code:
#!/bin/bash
for file in $(find . -name 'Test.dat*')
do
   echo "($file)"
done

I found the file I have searched for - but unfortunately the output is as:

Code:
(Test.dat)

But I would like to have the real name:

Code:
(Test.dat )

How could I do this?

Last edited by rbatte1; 12-14-2016 at 12:44 PM.. Reason: Added ICODE tags for clarity
# 2  
Old 12-14-2016
Hello API,

Could you please try following and let me know if this helps you(haven't tested it though).
Code:
find -type f -name "* "

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 12-14-2016
@RavinderSingh13: I tried it, but it is same output as described: (Test.dat)
# 4  
Old 12-14-2016
The problem is that the for loop is parsing the arguments it gets, based on the space.

If you let find control the loop, it should work:-
Code:
find . -name "Test.*" -exec echo "({})" \;

I get this output:-
Code:
$ touch "Test.dat "
$ find . -name "Test.*" -exec echo "({})" \;
(./Test.dat )
$

I hope that this helps, but I'm sure you need to use it in some wider context. How can we help you there?



Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 5  
Old 12-14-2016
The IFS (input field separator) default includes a space so even though "find" is pulling the right file name when the assignment happens to the variable "file" in your for loop the trailing spaces get chopped.

I think you may be looking for:

Code:
#!/bin/bash

IFS=$'\n'
for file in $(find . -name '*\ ' )
do
   echo "($file)"
done

# 6  
Old 12-14-2016
Quote:
Originally Posted by API
@RavinderSingh13: I tried it, but it is same output as described: (Test.dat)
Hello API,

I don't think there is a need of a loop and then putting find command's value to it, you could only use find command to print the file names.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 12-15-2016
If there is no sub directory, and not too many files, then you can simply print them
Code:
printf "(%s)\n" Test.dat*

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find files having filename containing specific date format

Hi, I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing. Could you please have any idea on this. trades_201604040000.out... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

2. UNIX for Dummies Questions & Answers

Find all files containing string not following symlinks CAT (modified) output content to /filename

This should recursively walk through all dirictories and search for a specified string in all present files, if found output manicured content (eg some regex) with CAT into a specified directory (eg /tmp/) one by one, keeping the original names This is what I have so far, which seems to... (1 Reply)
Discussion started by: lowmaster
1 Replies

3. Shell Programming and Scripting

How to find a file which are not ends with ".zip" and which are ends with "*.log*" or "*.out*"?

I am new to bash/shell scripting. I want to find all the files in directory and subdirectories, which are not ends with “.zip” and which are contains in the file name “*.log*” or “*.out*”. I know below command to get the files which ends with “.log”; but I need which are not ends with this... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. Shell Programming and Scripting

Find command error having space in filename

Hi, I am working in solaris.I am using below script to copy the files from /usr/tmp to /usr/gm But while running this it is not considering the files list after the filename having space in them. Example:- compile_custom_pll.sh conv_data_sqlload.sh conv_sqlload.sh Copy of... (5 Replies)
Discussion started by: millan
5 Replies

5. Shell Programming and Scripting

Find files greater than a particular date in filename.

I need a unix command which will find all the files greater that a particular date in the file name. say for example I have files like(filenaming cov : filename.YYDDMMSSSS.txt) abc.201206015423.txt abc.201207013456.txt abc.201202011234.txt abc.201201024321.txt efg.201202011234.txt... (11 Replies)
Discussion started by: lijjumathew
11 Replies

6. Shell Programming and Scripting

Perl Script to find the disk usage and to delete the files which is consuming more space

Hi All, I have written a script to check the file system usage and to delete the files which is consuming more space.Please check whether the script is corrcet #Script Starts here #!/usr/local/bin/perl #Program to find the disk space and to delete the older files #Checks the type of OS... (8 Replies)
Discussion started by: arunkarthick
8 Replies

7. UNIX for Dummies Questions & Answers

filename with white space

our user creates a text file with a white space on the filename. this same file is transfered to unix via automation tool. i have a korn shell script that reads these files on a input directory and connects to oracle database to run the oracle procedures which will load the data from each of the... (2 Replies)
Discussion started by: wtolentino
2 Replies

8. UNIX for Dummies Questions & Answers

sort and find duplicates for files with no white space

example data 5666700842511TAfmoham03151008075205999900000001000001000++ 5666700843130MAfmoham03151008142606056667008390315100005001 6666666663130MAfmoham03151008142606056667008390315100005001 I'd like to sort on position 10-14 where the characters are eq "130MA". Then based on positions... (0 Replies)
Discussion started by: mmarshall
0 Replies

9. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

10. UNIX for Advanced & Expert Users

Find and store files based on FileName and Modified Time

Hi, I am currently using the following command: files=(ls enuCPU??.????.exp ntuCPU??.????.exp) I need to now change the commmand to store the file names of files that have been modified before datetime equal to say '02/16/2008 20:30:00' What could I use? (2 Replies)
Discussion started by: edisonantus
2 Replies
Login or Register to Ask a Question