1

I'm on opensus 11.3 and I am looking for a bash script to do the following:

  1. Create directories and rename them from a .txt list, each new name is a new line on that .txt

  2. Copy file.php from to each new directory, and rename all file.php files in those directories to a specific name.

  3. Print a "/< php ? >/" string into the first line in each of those files.

I assume the best and fastest to accomplish this will be in bash, if you have another idea I will be happy to listen.

9
  • See my answer. You didn't say to what name the dirs should be renamed & to what name should be file.php renamed. Provide this information and I will update my answer accordingly Commented Apr 8, 2011 at 14:50
  • The folder names should taken by order from list.txt and the file indide is a specific name "filename.php". I tried What you wrote it does not create the folders. Commented Apr 8, 2011 at 15:01
  • Ok, see my updated answer. What about this dir renaming? Commented Apr 8, 2011 at 15:04
  • Great it does that, Thanks pajton, you saved me long time here. :) Commented Apr 8, 2011 at 15:09
  • let me ask you, what if the string that it prints inside will be the a php code that will like <php $city= "the folder name from the list" ?> ? Is there a way to do that ? Commented Apr 8, 2011 at 15:14

1 Answer 1

4

Edit:: This is the version modified according to OP's last comment:

#/bin/bash

while read name; do
    # prepare file to copy into new dirs
    echo "\<php \$city= \"$name\" ?\>" > tempfile
    cat file.php >> tempfile

    # create dir & copy modified file.php into it
    mkdir -p "$name"
    cp tempfile "$name"/filename.php
done < names.txt
Sign up to request clarification or add additional context in comments.

1 Comment

use mkdir -p, to avoid errors when crating subdirectories directly.

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.