|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Chose list of sub directories in a bash script file
Hi, I have a command in my bash script, searchDirectoryName.sh: Code:
DIR_NAME=$(find . -type d)
echo "${DIR_NAME}"Code:
. ./Dir1 ./Dir1/1.0.2.1 ./Dir2 ./Dir2/1.1 ./Dir3 ./Dir3/2.2.1 How can I select only following directory names with second subdirectoies and without first ./ in the DIR_NAME? Code:
Dir1/1.0.2.1 Dir2/1.1 Dir3/2.2.11 Finally substitute "/" to "_" for each name: Code:
Dir1_1.0.2.1 Dir2_1.1 Dir3_2.2.1 Thanks. Kind regards. Last edited by Franklin52; 03-07-2013 at 03:02 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
for DIR_NAME in $(find . -type d)
do
if [[ "$DIR_NAME" =~ \/[0-9]\. ]]
then
DIR_NAME="${DIR_NAME#\.\/}"
DIR_NAME="${DIR_NAME/\//_}"
echo "$DIR_NAME"
fi
done |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Cheers. |
|
#4
|
|||
|
|||
|
hope this helps. Code:
find . -type d |awk '{ gsub(/\.\//,"",$0); gsub(/\//,"_",$0);print }' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Separating list of input files (*.file) with a comma in bash script | TuAd | Shell Programming and Scripting | 7 | 05-31-2011 01:35 PM |
| Bash script: issue changing directories in script | Breakology | Shell Programming and Scripting | 5 | 05-26-2009 08:47 AM |
| a remove script taken in input a file which contain a list of directories | yeclota | Shell Programming and Scripting | 2 | 09-09-2008 10:56 AM |
| help with script to list directories | chassis | Shell Programming and Scripting | 2 | 09-13-2006 01:17 PM |
| Script to list changes in Directories | aojmoj | Shell Programming and Scripting | 2 | 11-22-2003 09:51 PM |
|
|