Ux2dos script

Hi all,
Does anyone know how to convert a good few files in a particular directory (unix) to dos files and place them in another directory?
I know this can be done with ux2dos but I am trying to come up with a shell script to do so

Dear lcclaj0,

I have a few to questions pose in response first:-

  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

HPUX v11.3

I just need a good script that can do the above as I am not the best at shell scripting

We are all here to learn from each other, not just to be a free script writing service.

Whilst I would be happy to help (and the only possible payment would be you pressing the :b:Thanks button) you need to show us what you have tried so far along with the errors so that we can suggest improvements.

There is no point in spoon feeding you an answer that you do not understand and cannot support when you need to adjust it in the future.

If you can't be bothered to try first (no matter how badly wrong it goes) and show us the attempt and the errors, then .........

1 Like

i'm willing to provide a small script for you this time, once and explain it as much as i can.

Hopefully we shall see in the future will user lcclaj0 ask simple question again without any tries, but lets assume he is new in scripting and is looking for a simple example.

INPUTDIR=/directorywithunixfiles
OUTPUTDIR=/directoryforoutput
[ -d $OUTPUTDIR ] || exit 1 # script will exit if $OUTPUTDIR is not a directory.
cd $INPUTDIR || exit 1 # script will exit if it's unable to change directory to $INPUTDIR, additionally it will print the cd command error on stderr
for i in * # for everything in $INPUTDIR 
do
   if [ -f "$i" ]; then # if it's a file use ux2dos utility on it, otherwise silently ignore.
   ux2dos "$i" > "${OUTPUTDIR}"/"$i"
   fi
done
cd - # return to directory the script has been issued from.

Directory /directoryforoutput (destination) will contain converted files with /directorywithunix (source) will contain original files, uneffected by operation (exception being modifed atime -access time, if used on filesystem, by default vxfs - yes.)

This is sample shell script with basic error handling.

Shell commands and constructs used :

  1. Variable declaration (directories used INPUTDIR OUTPUTDIR)
  2. Conditional operator ( || )
  3. Test constructs ( [ .. ] ) # man test
  4. for loop to iterate over the directory contents
  5. ux2dos utility to convert format.

Script will not go into subdirectories or process files with dots in names e.g .config

Hope that helps.
Best regards
Peasant.

1 Like

I will try this.. Thanks Peasant and correct I am a beginner at shell scripting..

Hi all, so I tried with this script and share it to a directory shared by samba but when I go to open the file on my windows machine the file is still in unix format which is all over the place :frowning:

So now you're in the situation Robin (rbatte1) warned you about.
What have you tried so far to find the cause? Did you see any diagnostic message when you ran the script? What was the return code? Does it work if you do what the script is supposed to do by hand for one file?

1 Like

I have tried running sed 's/$/\r/' < input.txt > output.txt ux2dos also

The script runs ok no errors and the file gets placed in the Output Directory like it is supposed to do. I have tried opening the file in word and Notepad but it is still messed up in unix format.

WHAT exactly do you expect sed 's/$/\r/' < input.txt > output.txt ux2dos to do? I think it's time now to dive into a detailed analysis of every single step and its results.

I thought that this would convert the UNIX format text file called input.txt to DOS format, writing the result to a file called output.txt.

So ... ?

Please be aware that YOU are sitting in the driver seat, nobody else can see what you see on the terminal nor control what you control. I F you want decent help, provide decent information - in this case that might be the results of the conversion steps, or the test steps as proposed by cero in post#8.

AND - read complete suggestions, to their entirety, AND answer ALL questions!

1 Like

So.... it goes through also but same result as the script.. Puzzled at the moment

Well, please show us your input, commands and output/errors. Please wrap them in CODE tags for clarity and to preserve spacing, which is important for indenting or fixed-width data.

Just saying it's gone wrong is like ringing up the local mechanic to say that your car has a problem and asking them to diagnose over the phone. Could it be flat battery, wrong key, flat tyre, out of fuel, damage/vandalism etc.

If you don't show us/tell us clearly, how will they know you have a broken bulb?

Robin

1 Like