Removing a filename which has special characters passed from a pipe with xargs


 
Thread Tools Search this Thread
Operating Systems AIX Removing a filename which has special characters passed from a pipe with xargs
# 1  
Old 05-19-2009
Removing a filename which has special characters passed from a pipe with xargs

Hi,

On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories.
Having said that I am more curious to know how this can be done.

an sample file name could be something as follows

Code:
12345678盇BCDEFGH,11T北北北北N盇DSKFHADFH盧,FR盬碒盪P北北北北北北北盋ASDFAS123

When I use the following command

Code:
find /history_directory -mtime +7 | xargs -I {} rm -fr {}

I get the message that states that an end quote is missing as follows

Code:
xargs: 0402-060 An end quote is missing from the string:

I am assuming it is because of the single quote in the file name.

When I try the following command in the directory where the file is located.

Code:
find . | xargs grep \'

I get the same results

Code:
xargs: 0402-060 An end quote is missing from the string:

How do I resolve this issue and make the above find command work?
Please advise.

Thx
Jerardfjay

Last edited by jerardfjay; 05-19-2009 at 08:19 AM.. Reason: More information
# 2  
Old 05-19-2009
Try this:

Code:
find /history_directory -mtime +7 | xargs rm -fr {} \;

Regards
# 3  
Old 05-19-2009
Sorry thats what I had to begin with

Quote:
Originally Posted by Franklin52
Try this:

Code:
find /history_directory -mtime +7 | xargs rm -fr {} \;

Regards
Franklin,

Thanks for your response, however that does not work. Please see below.

Code:
/home/user1/a> ls -ltr
total 0
-rw-rw-rw-   1 abcedfg  abcedfg          0 May 11 00:00 57470SWA_0030C2_____,REAR_R'L_____AEA900578A2
-rw-rw-rw-   1 abcedfg  abcedfg          0 May 11 00:00 57470SWA_0030C2_____,REAR_R'L_____AEA900578A1
/home/user1/a> find . -mtime +7
./57470SWA_0030C2_____,REAR_R'L_____AEA900578A2
./57470SWA_0030C2_____,REAR_R'L_____AEA900578A1
/home/user1/a> find . -mtime +7 | xargs rm -fr {} \;
xargs: 0402-060 An end quote is missing from the string: ./57470SWA_0030C2_____,REAR_RL_____AEA900578A2.
/home/user1/a>

Please advise.

Thx
Jerardfjay
# 4  
Old 05-19-2009
Quote:
Originally Posted by jerardfjay
Hi,

On AIX 5200-07-00 I have a find command as following to delete files from a certain location that are more than 7 days old. I am being told that I cannot use -exec option to delete files from these directories.
...
That's a big limitation. Additionally if GNU find/xargs was installed, their -0 option could have been used to handle the bad filenames... Maybe this will help:

Code:
find /history_directory -mtime +7  | 
             while read file
                do 
                   rm  -- "$file"   
                done

[ Tested on Solaris with non-GNU tools. Does not handle filenames with embedded newlines. ]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing special characters - Control M

I have developed a small script to remove the Control M characters that get embedded when we move any file from Windows to Unix. For some reason, its not working in all scenarios. Some times I still see the ^M not being removed. Is there anything missing in the script: cd ${inputDir}... (7 Replies)
Discussion started by: vskr72
7 Replies

2. Shell Programming and Scripting

removing a range of characters in a filename

hi, I have quite a bunch of files with annoyingly long filenames. I wanted to cut the range of characters from 9-18 and just retain the first 8 characters and the .extension. any suggestion how to do it. thanks much. original filename: 20000105_20000105_20100503.nc.asc output filename:... (4 Replies)
Discussion started by: ida1215
4 Replies

3. UNIX for Dummies Questions & Answers

Help with Removing extra characters in Filename

Hi, It's my first time here... anyways, I have a simple problem with these filenames. This is probably too easy for you guys: ABC_20101.2A.2010_01 ABD_20103.2E.2010_04 ABE_20107.2R.2010_08 Expected Output: ABC_20101 ABD_20103 ABE_20107 The only pattern available are the ff: 1) All... (9 Replies)
Discussion started by: Joule
9 Replies

4. Shell Programming and Scripting

Removing special characters

Dear Friends, I want to remove text between two patters. Problem is, it has random special characters like \ / | * ` ~ ! $ etc. These random special characters has no fixed length. But these special characters are appearing between a fixed pattern e.g. DM&^%#|#!\/?CT Expected output... (14 Replies)
Discussion started by: anushree.a
14 Replies

5. Shell Programming and Scripting

awk search pattern with special characters passed from CL

I'm very new to awk and sed and I've been struggling with this for a while. I'm trying to search a file for a string with special characters and this string is a command line argument to a simple script. ./myscript "searchpattern" file #!/bin/sh awk "/$1/" $2 > dupelistfilter.txt sed... (6 Replies)
Discussion started by: cue
6 Replies

6. Shell Programming and Scripting

Pipe to "xargs rm" : filename with spaces

Hi all, Am piping a list of files to "xargs rm -v". The files may have spaces in their names. Please advise how do i deal with it... :confused: Thanks. (3 Replies)
Discussion started by: coolatt
3 Replies

7. Shell Programming and Scripting

removing special characters @ EOL

How to remove special chracters @ END OF EACH LINE in a file file1.txt: 0003073413^M 0003073351^M 0003073379^M 0003282724^M 0003323334^M 0003217159^M 0003102760^M 0002228911^M I used the below command but it is not working ? perl -pi -e 's/^M\/g' file1.txt (6 Replies)
Discussion started by: ali560045
6 Replies

8. Shell Programming and Scripting

remove special characters from filename recursively

hi: i have several thousand files from users and of course they use all kind of characters on filenames. I have things like: My special report (1999 ) Lisa & Jack's work.doc crazy. How do I remove all this characters in the current dir and subdirs too? Thanks. (3 Replies)
Discussion started by: jason7
3 Replies

9. Shell Programming and Scripting

Open filename with special characters in Perl

Hi All, I am facing a weird problem. I have got a directory structure copied from windows to Linux. Some of the folders are named like /gfs/data/Dow Jones $5/ DJ FCBOT_O_tick_1998.zip /gfs/data/Dow Jones $5/ DJ FCBOT_O_tick_2000.CSV /gfs/data/Dow Jones... (6 Replies)
Discussion started by: mitrashatru
6 Replies

10. Shell Programming and Scripting

Removing special characters in file

I have file special.txt with the following data. <header info> 123$ty5%98&0asd 1@356fgbv78 09*&^5jkns43( ...........some more rows. In my output file, I want to eliminate all the special characters in my file and I want all other data. need some help. (6 Replies)
Discussion started by: srivsn
6 Replies
Login or Register to Ask a Question