0

i have tried this

$ls 
casts.c endian.c ptr.c signed-unsigned-representations.c signed-unsigned.c test-hard-link.c

$for i in *.c;do mv "$i" "$i"__swa.c; done

$ls
casts.c__swa.c endian.c__swa.c ptr.c__swa.c signed-unsigned-representations.c__swa.c signed-unsigned.c__swa.c test-hard-link.c__swa.c

and i know that because my i variable is *.c so when i try to rename and add the (__swa.c) part it just gets added on the variable name.

i need the files to be renamed like this:

casts__swa.c  endian__swa.c  ptr__swa.c  signed-unsigned-representations__swa.c                signed-unsigned__swa.c  test-hard-link__swa.c
Cyrus
  • 84,225
  • 14
  • 89
  • 153
suliman
  • 11
  • 3

2 Answers2

1

With Perl's standalone rename or prename command:

rename -n 's/\./__swa./' *.c

If output looks okay, remove -n.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
1

Using Bash's parameter expansion , you could do something like this:

for f in *.c; do
    echo mv "$f" "${f%%.c}"__swa.c
done

(Remove the echo of course, if it looks like it will do what you want)

But I generally rather use the more flexible rename using Perl, as suggested in the answer by Cyrus.

mivk
  • 13,452
  • 5
  • 76
  • 69