5 added 71 characters in body
source | link

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs -I{} mkdir -p «prefix»{}

I have made it so that folder numbers are one or more digits.

  • I have made it so that folder numbers are one or more digits.
  • Leave «prefix» blank, unless you want a prefix.

If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

The sed/rename language is very powerful, though complex. The main parts that you would use are s (as used here), and maybe next y, these are worth learning. You will also have to learn regular expressions (also used by grep, and other commands).

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

The sed/rename language is very powerful, though complex. The main parts that you would use are s (as used here), and maybe next y, these are worth learning. You will also have to learn regular expressions (also used by grep, and other commands).

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs -I{} mkdir -p «prefix»{}

  • I have made it so that folder numbers are one or more digits.
  • Leave «prefix» blank, unless you want a prefix.

If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

The sed/rename language is very powerful, though complex. The main parts that you would use are s (as used here), and maybe next y, these are worth learning. You will also have to learn regular expressions (also used by grep, and other commands).

4 added 264 characters in body
source | link

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

The sed/rename language is very powerful, though complex. The main parts that you would use are s (as used here), and maybe next y, these are worth learning. You will also have to learn regular expressions (also used by grep, and other commands).

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

The sed/rename language is very powerful, though complex. The main parts that you would use are s (as used here), and maybe next y, these are worth learning. You will also have to learn regular expressions (also used by grep, and other commands).

3 added 403 characters in body
source | link

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -es~[.]/folder[0-9]+/folder_~~ 's~[.]/folder[0-9]+/folder_~~' | xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -es~[.]/folder[0-9]+/folder_~~| xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

If you have a file (named list containing, the following, and you with to create a directory for each line name in file, where the directory name is just the part after ./folder?/folder_.

./folder1/folder_01_PAP_515151
./folder1/folder_04_PAP_654123
./folder2/folder_055_PAP_685413
./folder2/folder_100_PAP_132312
./folder3/folder_32_PAP_3513131
./folder3/folder_53_PAP_3213321
./folder3/folder_84_PAP_3313213

Then you can do.

cat list | sed -r -e 's~[.]/folder[0-9]+/folder_~~' | xargs mkdir -p

I have made it so that folder numbers are one or more digits.


If you wish to just rename the original folders/directories, keeping original content, then you can do:

Test with this one. Then remove the -n from rename, to do it for real.

find . -type d -name "*_PAP_" | rename -n 's~[.]/folder[0-9]+/folder_~~'

Note the search pattern is the same for rename as it is for sed. rename works on filenames, sed works on files or streams.

The options to sed:

  • -r use extended regular expressions (the dialect of regular expression to use).
  • -e The next arg is the expression (sed program).
  • 's~[.]/folder[0-9]+/folder_~~' the expression, quoted so that the shell does not interpret it.

The expression explained: s~[.]/folder[0-9]+/folder_~~

  • s do a search and replace
  • ~ the separator character it separates the expression into sections, you can use any character, but must use the same one each time. s~«search_for»~«replace_with»~«options» or using a different character s@«search_for»@«replace_with»@«options».
  • «search_for» a regular expression:
    • [.] a dot
    • /folder just what it says.
    • [0-9] a digit.
    • + one or more of the preceding atom (the digit) (so one or more digits).
    • /folder_ just what it says.
  • «replace_with» What to replace it with, in this case nothing.
  • «option» in this case note, others include i ignore case, g do it more that once (not just first string found).
2 added 403 characters in body
source | link
1
source | link