LinuxQuestions.org
Review your favorite Linux distribution.
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 09-26-2011, 10:01 AM   #1
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Rep: Reputation: Disabled
bash script to apply a command to a file to be printed


Hi all,

How could i apply unix2dos command to all files to be printed with a shell script in RHEL4.
Thanks in advance!
 
Old 09-26-2011, 11:43 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
How would you do a single file on the command line?

Where are all these files? (ie same directory or different places)

What have you tried?
 
Old 09-27-2011, 01:47 PM   #3
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Hi grail,

For a single file on command line, i would do

Code:
unix2dos test.txt
files are at different directories. I want the files to be printed to be modified by unix2dos command.
As i am new to CUPS printing, i have no idea where to start.
Thanks in advance!
 
Old 09-27-2011, 04:21 PM   #4
zk1234
4MLinux Maintainer
 
Registered: Oct 2010
Location: Poland
Distribution: 4MLinux, Slackware
Posts: 548

Rep: Reputation: 120Reputation: 120
If all the files are in the /XYZ directory (and its subdirectories), you can try:
Code:
cd /XYZ && find -name *.txt | unix2dos
For example: this will process all the *.txt files on your disk:
Code:
cd / && find -name *.txt | unix2dos
 
Old 09-28-2011, 12:34 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
So zk1234 has you on your way, although find can do all the heavy lifting:
Code:
find /top/level/directory -type f -name '*.txt' -exec unix2dos {} \;
If you want to confirm first that you have all the correct files you could do:
Code:
find /top/level/directory -type f -name '*.txt'
The quotes are important otherwise you might get file expansion (possible error in above post)
 
Old 09-28-2011, 11:26 AM   #6
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
Thank you zk1234 and grail for replies.

@grail:

Could you tell what
Code:
{} \
will do in your code
 
Old 09-28-2011, 11:49 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Have a look at the man page for find.
 
Old 09-28-2011, 02:02 PM   #8
linuxandtsm
Member
 
Registered: May 2011
Posts: 194

Original Poster
Rep: Reputation: Disabled
thanks!
 
  


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
Find and replace a string in a file using perl command from bash script koundinya749 Programming 5 02-15-2011 05:52 PM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 12:10 PM
[SOLVED] [bash]difference between script on command line and in file Wim Sturkenboom Programming 4 09-08-2008 03:20 AM
bash script to apply sed command only to a specific text area mauran Programming 6 07-13-2007 05:38 PM
Bash command/script to return group of file IHateFriction Programming 3 03-09-2007 01:31 PM


All times are GMT -5. The time now is 08:57 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