Dos2UNIX to skip binaries when run recurrsively


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Dos2UNIX to skip binaries when run recurrsively
# 1  
Old 11-02-2016
Dos2UNIX to skip binaries when run recurrsively

Greetings ..

I recently came across an issue with dos2unix and couldn't find an answer. I tried out in several methods and thought will reach for help

I am doing a recursive dos2unix on a folder that has text files, .class , jars , lib, txt etc .. in a unix server. The dos2unix by default should ignore the binaries (in my case class , jars , zip etc) is my understanding but in my case it converts these binary files (.class,.jars ) and I run in to issue as they are corrupted. Can you please help if I need to use differently..

I use ::
Code:
find . -type f -exec dos2unix {} {} \;

Let me know .. thanks for your patience in dealing with this .

Last edited by jim mcnamara; 11-02-2016 at 07:38 PM..
# 2  
Old 11-02-2016
Code:
find . -type f -exec grep -Iq . {} \; -and -print | xargs dos2unix -

This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 11-02-2016
You can use find based on file names I picked names randomly you need to select ones you want to exclude.

Code:
find /path/to/files -type f  !  \( -name '*.jar' -o -name '*.zip' -o -name '*.class' \) -exec dos2unix  {} {} \;

Test your list by simply not having an -exec clause in your test statement.

Is there a reason your IDE cannot produce .txt files without the windows \r carriage control character?

Note: rdrtx1 gave you an example based on GNU grep, which will work fine. You did not specify your platform
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 11-02-2016
Thanks Jim.

I have all files are in a code repository, my build system is in WIN and i need to copy back to several Unix destination servers. So compilation is on WIN and target is on Unix.

For doing below.,i need to know the all the file extensions, am i right ? is there a way that i can mention to ignore all "binary files". This will keep the scripts running for long time without issues ( if my 'source dir' get a new binary extension files)

Code:
find /path/to/files -type f  !  \( -name '*.jar' -o -name '*.zip' -o -name '*.class' \) -exec dos2unix  {} {} \;


Last edited by Scrutinizer; 11-03-2016 at 01:36 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return for Dos2UNIX

Hi, I have to test to see if dos2unix is installed on the machine. Right now I am typing in dos2unix and hitting ctrl C. Is there a better workaround for this. If dos2unix is there is need to print the statement saying its there and vice versa. How can i accomplish this. thank you in... (1 Reply)
Discussion started by: tarreddy
1 Replies

2. UNIX for Advanced & Expert Users

Dos2UNIX formatting problem

Hi, I was trying to dos2unix a file that has some special characters but dos2unix converted those into different format. I am working on sun server. I guess the default for dos2unix on sun server is ISO format . Can i change the format so that it does the conversion in UTF format? Because I... (3 Replies)
Discussion started by: abhi1988sri
3 Replies

3. Shell Programming and Scripting

problem with dos2unix command

hi friends i am using the dos2unix command to remove the ^M characters coming at the end of each line , but i getting the folowing message: > dos2unix file.sql could not open /dev/kbd to get keyboard type US keyboard assumed could not get keyboard type US keyboard assumed ---------file... (6 Replies)
Discussion started by: neelmani
6 Replies

4. UNIX for Dummies Questions & Answers

return value of dos2unix

if (my $temp2=$b2e_r->cmd(cmd=>"dos2unix $b2e_file_name")) Even if it fails as, Jul 25 17:17:02 dos2unix /volume/systest/hello_manoj.results dos2unix /volume/systest/hello_manoj.results dos2unix: converting file /volume/systest/hello_manoj.results to UNIX format ... Failed to open... (3 Replies)
Discussion started by: manojn
3 Replies

5. Shell Programming and Scripting

dos2unix

hi, need some urgent inputs..... I have a folder, which has both files and directories as its contents. I want to convert all the files (Excluding the directories) from dos to unix mode using the command 'dos2unix'..... please can any one help me in providing the command to convert... (3 Replies)
Discussion started by: cmaroju
3 Replies

6. UNIX for Dummies Questions & Answers

Regarding dos2unix command

Hi, Does anyone know, how to use dos2unix command for binary files? When i am using the command, the binary file gets converted to ASCII file. I want binary file to remain in the binary format. (4 Replies)
Discussion started by: agarwal
4 Replies

7. UNIX for Dummies Questions & Answers

dos2unix equivalent in hpunix

hi, what is the dos2unix equivalent in hpunix ?? (10 Replies)
Discussion started by: risshanth
10 Replies

8. Linux

dos2unix permission problem

Hi All, I want to use the command "dos2unix" to format the file line break from win to unix, but after changing the file permission has been change to 600. how can i keep the original permisson after formatting? Many thz (2 Replies)
Discussion started by: eric_wong_ch
2 Replies

9. UNIX for Advanced & Expert Users

Asking on dos2unix syntax

Hi, like to ask why when i tried to run my .sh file to convert maybe a text file using dos2unix -ascii ${DATAFILE5} ${DATAFILE5} i got an error saying : could not open /dev/kbd to get keyboard type US keyboard assumed could not get keyboard type US keyboard assumed Is it because we dun like... (4 Replies)
Discussion started by: blueberry80
4 Replies

10. UNIX for Dummies Questions & Answers

any pitfalls to using $dos2unix function?

Greetings- are there any pitfalls/costs/etc to be aware of using the "$dos2unix <filename>" utility in Solaris 8? does it really work as simply as it's described / recommended in other threads ? We want to establish the procedure / develop a script or procedure to automatically strip out ^M... (1 Reply)
Discussion started by: gsumers22texas
1 Replies
Login or Register to Ask a Question