0

I am trying to create a script that will go through several steps on specific files in a directory. Each step work file at a prompt. It's when I use 'for' to work through the needed files that isn't working.

here is the script and starting text file.

#lab2dno.sh
#
#use cygwin
#cygwin
#work in %RAM%:\
cd '/cygdrive/e'
  # delete header lines
tail +4 preg.txt > file1.txt
  # split into herdcode.tx1 from %RAM% (e) in bash-3.2
awk -F "," '{close(f);f=$1}{ print > f".tx1" }' file1.txt
  #file list (no ext)
ls -1 *.tx1 | sed 's/\(.*\)\..*/\1/' > hc.ls1
  # delete extra fields (and rename works @ prompt))
  # cut -d "," -f 2,3,6 41300090.tx1 > 41300090.tx2
  # this one does not work
for i in hc.ls1; do cut -d "," -f 2,3,6 $i > $i.tx2;done
  # reorder fields and rename (works at propmt)
  # awk -F, '{ print $2,$3,$1}' *.tx2 > *.tx3
  # this one does not work
for i in *.ls1; do awk -F, '{ print $2,$3,$1}' $i > $i.DNO;done

...preg.txt...

MNDHIA Export

Name,Test Date,ID,Tag,Final Calculation,Symbols (Final Calculation),1,Parachek
41300090,1/25/2013,1636,56439256,-0.008,OPEN,1,Parachek
41300090,1/25/2013,1238,67046268,-0.017,OPEN,1,Parachek
41732189,1/29/2013,304,55567637,-0.006,OPEN,1,Parachek
41732189,1/29/2013,415,55646609,-0.007,OPEN,1,Parachek
4

1 回答 1

0
for i in hc.ls1; do cut -d "," -f 2,3,6 $i > $i.tx2;done

这行不通。在脚本顶部使用set -x,它将打开调试模式并回显每个命令。

您在上面的行中所做的是将值设置为ito hc.ls1。你真正想要的是将它设置为里面列出 hc.ls1的每个值:

for i in $( cat hc.ls1 ) ; do cut -d "," -f 2,3,6 $i > $i.tx2;done
于 2013-02-07T21:19:04.653 回答