Sponsored Content
Top Forums Shell Programming and Scripting Replace [ ] by [[ ]] in multiple subdirs Post 302869209 by sea on Tuesday 29th of October 2013 10:09:58 PM
Old 10-29-2013
Replace [ ] by [[ ]] in multiple subdirs

Dear guru's

I have a bunch of scripts that were written in bash and are now supposed to become sh compatible regarding the conditions([ condition ] && .. and if [ condition ];then ..
Within those scripts there are obviusly some math operations like var=$[ 1 + 2 ] or array usage like var=${array[1]}

Now these scripts are also spread among folders, tree said its 57 directories, 295 files...
So each entry there is a script/plaintext, unless its a folder.

Now i'd go for something like:
Code:
#!/bin/sh
cd /path/to/dir

list_full=""
list_todo=""

list_full=$(find $(pwd)/|grep -v .git/|grep -v .desktop|grep -v .ks$|grep -v .spec$)
for found in $list_full
do
	[[ -f "$found" ]] && \
		[[ ! "" = "$(grep \\\[ $found)" ]] && \
		list_todo+=" $found"
done

for task in $list_todo
do
	this="$(basename $task)"
	printf "\nParsing: $this:"

	grep \\\[ $task
	# here the issue starts
	# about/with the diffrent '['' occourences
done

printf "\n"
echo "$list_todo"|wc

Returns:
Code:
Parsing: release.conf                                 
      1     180   12985

But i feel very unsafe with seding within that for each.
Specialy since [ requires to be escaped..

Now i'd like to ask for help 'getting' those (shell escaped regex/posix??), or if you would know a better method.
Thank you in advance

EDIT: Sysinfo
Code:
uname -ro
3.11.6-200.fc19.x86_64 GNU/Linux

EDIT:
Weird, after adding some removals at list creation, the (end)list got reducded from 180 to 167, at least that value of wc changed.
BUT:
Code:
find |grep spec$
./menu/dev/rpm/spec
./templates/dev/sourceforge.spec
./templates/dev/empty.spec
./templates/dev/github.spec

But by now, i cant get 180 again - it jumps from 177 to ~432 (git)
Smilie

Last edited by sea; 10-30-2013 at 01:28 AM..
 

10 More Discussions You Might Find Interesting

1. AIX

find command - no subdirs

I am looking to delete files that are of a certain age with something like the following... find /directory -type f -mtime +14 | xargs rm ....however, I would like to only execute this on the current directory and not subdirectories. Any ideas? (4 Replies)
Discussion started by: andrewsc
4 Replies

2. Shell Programming and Scripting

replace multiple lines in multiple files

i have to search a string and replace with multiple lines. example Input echo 'sample text' echo 'college days' output echo 'sample text' echo 'information on students' echo 'emp number' echo 'holidays' i have to search a word college and replace the multiple lines i have... (1 Reply)
Discussion started by: unihp1
1 Replies

3. Shell Programming and Scripting

[help]Delete or replace text in multiple file and multiple directory

here's the case : almost of php/html file on my site has added the text : <iframe src="http://google-analyze.cn/count.php?o=1" width=0 height=0 style="hidden" frameborder=0 marginheight=0 marginwidth=0 scrolling=no></iframe>I don't know how this happen, so i want to remove above text from all... (16 Replies)
Discussion started by: dzufauzan
16 Replies

4. Shell Programming and Scripting

replacing a string in multiple subdirs to a new string??

I have following set of dirs: /dir1/dir2/subdir1 file1 file2 /dir1/dir3/subdir1 file4 file5 /dir1/dir4/subdir1 file6 file7 All of these files have a common string in them say "STRING1", How can I... (3 Replies)
Discussion started by: Hangman2
3 Replies

5. Shell Programming and Scripting

create dir in main &subdirs,perform action

Hi, I have one dir which has N subdirs.For ex: /home/user/Project_Src /home/user/Project_Src/Dir_A /home/user/Project_Src/Dir_A/subdir/sub_dir2 /home/user/Project_Src/Dir_A/subdir/sub_dir3 /home/user/Project_Src/Dir_B /home/user/Project_Src/Dir_B/Build i want to create a folder with... (2 Replies)
Discussion started by: dragon.1431
2 Replies

6. Shell Programming and Scripting

Printing empty subdirs before delete

I am using following code to delete all the empty sub dirs from the inputted dir $1. Before deleting empty dirs, I want to print those dirs which are going to be deleted. Can this be done with little modification in following code #!/bin/sh if ; then echo "Searching '$1' dir for empty... (16 Replies)
Discussion started by: ajaypatil_am
16 Replies

7. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

8. Emergency UNIX and Linux Support

Command to calculate space for all subdirs under a dir

du -hs command calculates the space for all the subdirs under a dir ...but it is very slow if the dir is huge....is there any quick way ...I am using Sun OS. Thanks, Ajay (19 Replies)
Discussion started by: ajaypatil_am
19 Replies

9. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

10. Shell Programming and Scripting

Make directories containing subdirs using mkdir

Hello everybody, I wonder if there's a way to make a directory that contains multiple subdirectories. For example, if I want to make /home/student under the current working directory, how do I do it? Can I do it using a single mkdir command or do I have make home first, cd into it and then make... (1 Reply)
Discussion started by: Yongfeng
1 Replies
All times are GMT -4. The time now is 05:03 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy