On 10/23/18 11:46 AM, francky.leyn@telenet.be wrote:
> Hello,
>
> I just destroyed 3 days of scaninng work. This was the command:
>
> ls p.*.png | sort -t. -k2 -n | gawk '{ printf("mv '\''%s'\'' '\''p. %d.png'\''\n", $0, NR+6) }' | bash [ mailto:bug-coreutils@gnu.org ]
>
> The problem was that the sequence of mv command resulted in one .png file:
>
> mv 'p. 123.png' 'p. 124.png'
> mv 'p. 124.png' 'p. 125.png'
> mv 'p. 126.png' 'p. 127.png'
>
> The result is that you end up with one file: 'p. 127.png'.
outch, sorry for your loss.
> When you look at the commands (without the trailing bash), you think it's ok because you think declaratively. However, this thing works imperative/procedural.
As you said, the problem originated from a logic error in the counting
for the new names of the files.
Didn't you run that without the executing "| bash" first?
> Hello,
>
> I just destroyed 3 days of scaninng work. This was the command:
>
> ls p.*.png | sort -t. -k2 -n | gawk '{ printf("mv '\''%s'\'' '\''p. %d.png'\''\n", $0, NR+6) }' | bash [ mailto:bug-coreutils@gnu.org ]
>
> The problem was that the sequence of mv command resulted in one .png file:
>
> mv 'p. 123.png' 'p. 124.png'
> mv 'p. 124.png' 'p. 125.png'
> mv 'p. 126.png' 'p. 127.png'
>
> The result is that you end up with one file: 'p. 127.png'.
outch, sorry for your loss.
> When you look at the commands (without the trailing bash), you think it's ok because you think declaratively. However, this thing works imperative/procedural.
As you said, the problem originated from a logic error in the counting
for the new names of the files.
Didn't you run that without the executing "| bash" first?
I did, but my coin hasn't fallen. What I should have done, is after seeing the result when executing without the "| bash", is change the command to:
ls p.*.png | sort -t. -k2 -n | gawk '{ printf("mv -i '\''%s'\'' '\''p. %d.png'\''\n", $0, NR+6) }' | tac | bash