LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2012, 08:28 AM   #1
keerti
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
help with a shell script that runs 'dos2unix' command on files in a directory,


hi all,
i need a shell script that runs <dos2unix 'file1.sh' 'file2.sh'>
on all the files that are present in a directory. the files are not in any sequence , and they will be named in no order.
please help , as this is a tedious process in my work everyday. this script could help me save hours of manual work!
 
Old 01-30-2012, 08:43 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Do you mean automatically? You can set up a script, and run it with cron. What have you come up with so far?
 
1 members found this post helpful.
Old 01-30-2012, 08:55 AM   #3
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Something like:

Code:
find . -maxdepth 1 -type f | xargs -I "{}" dos2unix "{}"
Runs dos2unix against all the the files in the current working directory
 
Old 01-30-2012, 09:04 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
How about a simple loop and perform each task on the files found?
 
Old 01-30-2012, 09:53 AM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Why not just use shell globbing
Code:
dos2unix *.sh
 
1 members found this post helpful.
Old 01-30-2012, 10:05 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Or if dos2unix can only work on one file at a time:

Code:
for i in *.sh; do dos2unix "$i"; done
 
1 members found this post helpful.
Old 01-30-2012, 10:06 AM   #7
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Why write shell script in dos env anyway
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dos2unix command in shell scripting pdiv Linux - Server 3 07-05-2011 02:06 PM
Shell script to automatically delete files with the same name as the parent directory pratap.iisc Programming 9 10-12-2009 10:17 AM
help with shell script to avimerge only some files from a directory Neilevan814 Programming 7 10-08-2009 02:02 PM
Using Variables in a Command that uses a Directory (Shell Script) CrimsonSkyZS Linux - General 4 01-11-2006 03:18 PM
Specifying target directory for command in bash shell script? spectrescape Programming 1 07-22-2004 05:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration