سؤال

I'm trying to take all files of a certain extension, rename them, apply a script to them, and then rename them again. I'm running into something weird.

For the first step of this, I'm trying to apply the following command

for f in *.FDC; do mv $f ${f%FDC}FDCTMP1 done

Which, I believe, should, for all files of type .FDC, apply the mv function to them, resulting in files renamed as *.FDCTMP1.

When I try to run this, the $ in the command line turns to a >, and I'm unable to do anything. I've run into this problem in the past and I don't really know what's going on. Every time this happens I have to close out my putty instance and start a new one.

The next step is applying my script to the newly renamed .FDCTMP1 files. I'm not quite sure I got this right, but here's what I'm trying:

for f in *.FDCTMP1; do more $f | a bunch of sed and awk stuff here

I was originally testing this script with more filename | sed & awk stuff, and wasn't positive how I would change that functionality to taking each filename in the loop.

then, I want to apply the same idea as in step 1, to rename the filetype again:

for f in *.FDCTMP1; do mv $f ${f%FDCTMP1}FDCTMP2 done

I think I supplied too much info about my problem, I think the main issue is this part:

for f in *.FDC;

If it's relevant, I'm in kornshell

هل كانت مفيدة؟

المحلول

The prompt changes from $PS1 to $PS2 because the for command has not seen done -- you're missing a semi-colon after the mv command:

for f in *.FDC; do mv $f ${f%FDC}FDCTMP1 done
#---------------------------------------^

It sounds like you don't need 3 loops

for f in *.FDC; do
    tmp1=${f}TMP1
    mv "$f" "$tmp1"
    # do stuff with "$tmp1"
    mv "$tmp1" "${f}TMP2"
done

نصائح أخرى

In this command line:

for f in *.FDC; do mv $f ${f%FDC}FDCTMP1 done

you're missing the semi-colon before done:

for f in *.FDC; do mv $f ${f%FDC}FDCTMP1; done

As it was, you'd written code to pass three arguments to mv, and the shell was still looking for done as the first word of a command. You can type done on a line on its own, or after a semi-colon (or after an & that places a command in background).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top