Thread: shell script to process files and write out new file with different extension
i have ascii lidar files need have first column in each line removed them ready xyzi format of ascii 3d feature class tool. wanted make list of files in folder suffix .gnd , output modified data files same name txt suffix original ascii files not modified.
used had xp machine unix services windows installed somehow let me use linux cut command inside dos bat file:
the dos %~ can give lot of useful file name manipulations. installed unix services windows on new win 7 64 machine, , don't understand why, cut not available bat files on new machine, although can start unix c or k shell cut available %~n trick not.code:for %%f in (*.gnd) call :sub %%f %%~nf goto:eof :sub cut -d" " -f2-4 %1 > %2.txt
seems linux shell scripting i'm stuck @ how change extension of output file name.
got started python, got stuck:
then stuck. guess need new line inside first loop write file new file name .txt suffix, , haven't figured out how file name stripped of suffix.code:env.workspace = "g:/elevation/lidar2010/points/asc_grounds" filesuffix = ".gnd" txtlist = arcpy.listfiles("*" + filesuffix) file in txtlist: line in open("my file"): parts = line.split(" ") print " ".join(parts[1:4])
that's easy, bash has toys simple text manipulationseems linux shell scripting i'm stuck @ how change extension of output file name.
http://www.gnu.org/software/bash/man...eter-expansion
${f%.*}.txt removes shortest possible .(anything) from right side of filename , glues result .txtcode:for f in *.gnd; cut -d' ' -f2-4 "$f" > "${f%.*}.txt"; done
Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] shell script to process files and write out new file with different extension
Ubuntu
Comments
Post a Comment