Sponsored Content
Top Forums Shell Programming and Scripting Script to find only files that contain pattern Post 302952735 by newbie2010 on Friday 21st of August 2015 09:45:05 AM
Old 08-21-2015
Script to find only files that contain pattern

Actually I googled it and found != *Frequent* works!
So now I have zero questions
Thanks for reading, anyway!

Actually I got this working see below. I just now have one question:

How do you use a test condition (such as with Frequent) that takes whitespace into account
for example, if the file is Frequent List Home Items?
At this point the condition breaks up the file

Code:
MYDIR="/local/mnt/Lists"
eval cd $MYDIR for i in  `ls -d */` ; do (cd $i && for file in *; do [[ -d 2015 ]] ||  mkdir 2015; cd "2015"; [[ -d 01-January ]] ||  mkdir 01-January; cd ".."; dir=$(echo "$i"|sed 's/\/$//g');if [[ -f "$file" ]] && [[ "$file" != M-* && "$file" != Frequent ]]; then echo mv "$file" /netapp/bank/vol0/vertices/Move\ Lists/$dir/extras; fi;done);done

Code:
MYDIR="/local/mnt/Lists"
eval cd $MYDIR
for i in  `ls -d */` ; do (cd $i; echo $i && for file in *; do
[[ -d 2014 ]] || mkdir 2014
cd "2014"
[[ -d 01-January ]] || mkdir 01-January
[[ -d 02-February ]] || mkdir 02-February
[[ -d 03-March ]] || mkdir 03-March
[[ -d 04-April ]] || mkdir 04-April
[[ -d 05-May ]] || mkdir 05-May
[[ -d 06-June ]] || mkdir 06-June
[[ -d 07-July ]] || mkdir 07-July
[[ -d 08-August ]] || mkdir 08-August
[[ -d 09-September ]] || mkdir 09-September
[[ -d 10-October ]] || mkdir 10-October
[[ -d 11-November ]] || mkdir 11-November
[[ -d 12-December ]] || mkdir 12-December
cd ".."
dir=$(echo "$i"|sed 's/\/$//g')
if  [[ "$file" != *20[1-2][0-9]* && "$file" != M-* ]];
then echo mv "$file" /tmp/additions;
fi
done);done

It works just fine - the only problem is that it will try to move all the directories as well as files. I've tried the following to stop this but it hasn't worked:

Code:
dir=$(echo "$i"|sed 's/\/$//g')
if  [[  -f "$file" ]] && [[ "$file" != *20[1-2][0-9]* && "$file" != M-* ]];
then mv "$file" /local/mnt/Lists/$dir

What I get with this is nothing is moved..

If I do not use
Code:
[[ -f $file ]]

then directories are picked up, if I do use it, then nothing is moved.

Does anyone have any ideas?

I think I will try the find command.

Last edited by newbie2010; 08-21-2015 at 11:40 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

find pattern in FILES and replace it ??

Hi How can I looking for a pattern found in more than one file and replace it with anther pattern this what I was used: find . -name "account.adrs" -depth -follow -exec grep -l "Email = ;" {} \; this print the files name -which is account.adrs- and its path -which is deferent for each... (4 Replies)
Discussion started by: tamer
4 Replies

2. Shell Programming and Scripting

How to find files which has more than one occurance of pattern

Hello Everyone, Please help me in finding out the solution. The problem is .. lets say i have 600 files in a directory. All 600 files are shell script files. Now i need to find out the files which contains a pattern "SHELL" more than once. No matter how the pattern occurs , it can be in... (10 Replies)
Discussion started by: Prahlad
10 Replies

3. UNIX for Dummies Questions & Answers

Find files matching a pattern

Hi, I am writing a BASH shell script. I would like to count all the files in the CURRENT directory matching a specific pattern. Could someone suggest the best/simplest way to do this. I have thought of these solutions (for simplicity the pattern is all files starting with A): ls -1 *A | wc -l... (5 Replies)
Discussion started by: msb65
5 Replies

4. UNIX for Dummies Questions & Answers

find files NOT matching name pattern

Hi, I have following files in my directory: /TESTDONTDEL> ls -alt total 14 drwxr-xr-x 2 oracle dba 1024 May 15 06:30 . -rw-r--r-- 1 oracle dba 40 May 15 06:30 exception.txt -rw-r--r-- 1 oracle dba 19 May 15 06:22 ful_1234_test1.txt -rw-r--r-- 1... (2 Replies)
Discussion started by: sagarparadkar
2 Replies

5. Shell Programming and Scripting

To find the files with pattern and display

Hi all, Im looking for a script(bash,perl) to find the files which has content with ORA (Mostly will be from log file)if we find those content,need to send a mail alert to the team members with the files which are matched. This script should run daily so that it should search for the files... (1 Reply)
Discussion started by: preetha_83
1 Replies

6. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

7. Shell Programming and Scripting

How to find files in a pattern directory?

Hi, I have more than 1000 directories under one directory (lets says under /home/). Sub directories are like A1 to A100,B1 to B100 etc.. Here my problem is I need to find the files older than 10 days in the directories which starts with A*. I tried some thing like this which is not... (2 Replies)
Discussion started by: shhrikanth
2 Replies

8. Shell Programming and Scripting

Help me to find files in a shell script with any matching pattern

Hi friends.. I have many dirs in my working directory. Every dir have thousands of files (.jsp, .java, .xml..., etc). So I am working with an script to find every file recursively within those directories and subdirectories ending with .jsp or .java which contains inside of it, the the pattern... (3 Replies)
Discussion started by: hnux
3 Replies

9. UNIX for Dummies Questions & Answers

find Search - Find files not matching a pattern

Hello all, this is my first and probably not my last question around here. I do hope you can help or at least point me in the right direction. My question is as follows, I need to find files and possible folders which are not owner = AAA group = BBB with a said location and all sub folders ... (7 Replies)
Discussion started by: kilobyter
7 Replies

10. UNIX for Dummies Questions & Answers

UNIX script to find existences of files with a pattern in name

Hi My requirement is as follows. In a particular source directory say /home/Source, I need to search for filename with the following pattern. Bank_YYYYMMDD.txt and if the files with patterns are found them move them to archive directory /home/Source/Archive. The script should not do... (8 Replies)
Discussion started by: b.joe
8 Replies
NPM-RUN-SCRIPT(1)                                                                                                                NPM-RUN-SCRIPT(1)

NAME
npm-run-script - Run arbitrary package scripts SYNOPSIS
npm run-script <command> [--silent] [-- <args>...] alias: npm run DESCRIPTION
This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts. run[-script] is used by the test, start, restart, and stop commands, but can be called directly, as well. When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directly-run scripts. As of ` https://blog.npmjs.org/post/98131109725/npm-2-0-0, you can use custom arguments when executing scripts. The special option -- is used by getopt https://goo.gl/KxMmtG to delimit the end of the options. npm will pass all the arguments after the -- directly to your script: npm run test -- --grep="pattern" The arguments will only be passed to the script specified after npm run and not to any pre or post script. The env script is a special built-in command that can be used to list environment variables that will be available to the script at run- time. If an "env" command is defined in your package, it will take precedence over the built-in. In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix. For example, if there is a devDependency on tap in your package, you should write: "scripts": {"test": "tap test/*.js"} instead of "scripts": {"test": "node_modules/.bin/tap test/*.js"} to run your tests. The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe. The actual shell referred to by /bin/sh also depends on the system. As of ` https://github.com/npm/npm/releases/tag/v5.1.0 you can customize the shell with the script-shell configuration. Scripts are run from the root of the module, regardless of what your current working directory is when you call npm run. If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH. If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install, just in case you've forgotten. You can use the --silent flag to prevent showing npm ERR! output on error. You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain. SEE ALSO
o npm help 7 scripts o npm help test o npm help start o npm help restart o npm help stop o npm help 7 config January 2019 NPM-RUN-SCRIPT(1)
All times are GMT -4. The time now is 10:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy