bhanu146
bhanu146

Reputation: 45

how to iteratively move files/folder using grep pattern matching

I am trying to iteratively move the code files/folders from one directory to another as part of the continuous integration and for that, I am using the below code block.

for i in $HOME/gitstage/frolit/* ; do 
    if [ echo "$i" | grep -v '*db.sqlite3*|*bitbucket-pipelines.yml*' ]; then
        echo "$i"
    fi
done

Here I am trying to restrict two files db.sqlite3 and bitbucket-pipelines.yml from moving into the destination directory. But somehow this is not working out. Could anyone please help?

Upvotes: 0

Views: 259

Answers (2)

Phoenix
Phoenix

Reputation: 1

for i in $HOME/gitstage/frolit/* ;
do
if [[  "${i}" = *"db.sqlite3"* ]] || [[ "${i}" = *"bitbucket-pipelines.yml"* ]];
then
continue
fi
mv  $i   /target/directory  ####target directory  where   you want  to move the   files to
done

This should work fine in both bash and ksh even in older versions. Just make sure to check for if syntax with your shell and modify above if accordingly.

Upvotes: 0

Cyrus
Cyrus

Reputation: 88583

With bash 3.0 or newer:

if [[ ! "$i" =~ .*(db.sqlite3|bitbucket-pipelines.yml).* ]]; then

Upvotes: 1

Related Questions