4

How I can copy all file *.html to *.php with For loop?

help me...

this my script :

#!/bin/bash
list="$(ls *.html)"
for i in "$list"
do
  newname=$(ls "$i" | sed -e 's/html/php/')
  cat beginfile > "$newname"
  cat "$i" | sed -e '1,26d' | tac | sed -e '1,21d' | tac >> "$newname"
  cat endfiel >> "$newname"
done

or you have another ide ?

3 Answers 3

6
for f in *.html; do cp $f ${f%.html}.php; done
Sign up to request clarification or add additional context in comments.

Comments

3

Here you go:

for i in *.html; do mv "$i" "${i%.html}.php"; done

In RedHat Linux and derivatives there is a rename utility that simplifies this to:

rename .html .php *.html

In Debian Linux and derivatives there is a rename utility that simplifies this to:

rename 's/.html$/.php/' *.html

Check man rename or rename --help to see how to use the implementation you have. Sometimes the utility is called rename.pl instead of simply rename.

Comments

1

Can omit the for loop altogeather if you have perl packages installed.

#!/bin/bash
rename 's/html/php/' *.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.