LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
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: 360

Rep: Reputation: 40
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: 9,485

Rep: Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864Reputation: 2864
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: 242Reputation: 242Reputation: 242
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,433

Rep: Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044Reputation: 2044
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: 242Reputation: 242Reputation: 242
Why write shell script in dos env anyway
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 05:05 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration