Skip to main content

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:
code:
for %%f in (*.gnd) call :sub %%f %%~nf   goto:eof    :sub  cut -d" " -f2-4 %1 > %2.txt
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.

seems linux shell scripting i'm stuck @ how change extension of output file name.

got started python, got stuck:
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])
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.

seems linux shell scripting i'm stuck @ how change extension of output file name.
that's easy, bash has toys simple text manipulation
http://www.gnu.org/software/bash/man...eter-expansion

code:
for f in *.gnd; cut -d' ' -f2-4 "$f" > "${f%.*}.txt"; done
${f%.*}.txt removes shortest possible .(anything) from right side of filename , glues result .txt


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

Popular posts from this blog

Could not place because the source rectangle is empty

Thread: Using smartcard reader with vpnc

Adobe Font Folio 7.0 or just 7?