LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need to convert a large number of file types from none standard to txt (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-convert-a-large-number-of-file-types-from-none-standard-to-txt-758228/)

metalme 09-28-2009 09:14 AM

Need to convert a large number of file types from none standard to txt
 
I have on my windows machine several hundred files that are a format of .nc .ncs for a CNC machine. I need to convert them to txt which is something as easy as opening in notepad and then saving as .txt but there are so many that this kind of action would take way too long.

The reason I am writing the linuxquestions is because I would feel more comfortable in loading a live CD and using some sort of terminal command to do this than I would to download one of the many "freeware" type programs I have found for windows (even more so since I have had a root kit before and had to start all the way over to get rid of it).

I need to know:

1. Is this possible to do with the terminal without super advanced knowledge.

2. Can one please point me in the right direction; something to read or an example

theNbomr 09-28-2009 12:30 PM

It sounds like you need to simply rename the files. If this is the case, then a simple bash script can easily do this. First thing to do is backup the files, because you don't want to practice shell scripting on your only copy of the files (duh...).

This should get you started. You can either make it into a shell script, or just run the commands from a commandline, since it is evidently a one-shot process.
Code:

for cncfile in *.nc;  do echo mv $cncfile $( basename $cncfile ".nc"  ).txt; done
for cncfile in *.ncs; do echo mv $cncfile $( basename $cncfile ".ncs" ).txt; done

Run the script/commandline, and when you are satisified that it will do the right thing, remove the 'echo' command, to have it actually perform the deed.
If the files need to be processed in some way, you will need to specify what changes need to be performed.

--- rod.

choogendyk 09-28-2009 05:46 PM

It's a little hard to google details on .nc, .ncs, & CNC, however, it seems they are basically ascii text files containing the numerical control command language and with the extension .nc. That would be similar to a C program, which contains C program language in ascii text format and has a .c extension. One of the standard .nc formats was derived from the Gerber Plotter file format.

Anyway, that basically supports theNbomr's assumption that renaming is all that is required. His two lines of code look good, as well as his suggestion to test with the echo in place first. I would also make a backup of the files before proceeding just as a standard precaution.


All times are GMT -5. The time now is 03:16 PM.