Tag Archives: GREP

Changing the variable using awk?

By emily

Dear all,
I have kind of used both the awk/sed command and found them really useful.
But at the necessity I am having right now, I need help.
Actually, I would like to do the following in file script.sh

Code:


PATH535[1]="/eos/uscms/store/user/pooja04//analysis2012/535/mc/summer12/002/tt/"


there is whole script which works all fine, now my present task is to somehow read the RED LINE , and
change the “tt” to various varaible.
So I have something in mind as:

Code:

GREP[1]="ttbar"
GREP[2]="DYJets50"
GREP[3]="zgamma"
GREP[4]="mJetA"
GREP[5]="mJetB"

for FileNameIndx in "${GREP[@]}"
do
change the tt in script.sh to GREP[1]
do something ......
done


Can somebody help me with the BLUE color command, how shall I implement that?

thanks in advance
emily

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

GREP loop

By jcllns1

Use and complete the template provided. The entire template must be completed. If you don’t, your post may be deleted!

1. The problem statement, all variables and given/known data:
I need to search through the users home directories for keywords, display them. The code listed below will show me the first result but I am not sure how to loop through the results. I am not sure how to make a loop work.

I then need to exclude users from the search if what that script found was phrase that is acceptable. So if the script is ran again the user will not come up again in the search.

I am using a file with a list of the word to search, could I do this with the exclusions as well?

2. Relevant commands, code, scripts, algorithms:
ECHO
GREP

3. The attempts at a solution (include all code and scripts):

Code:

RESULT=`grep -irf searchwords /home`

FLOC=`echo $RESULT | cut -d : -f 1`

UNAME =`echo $FLOC | cut -d / -f 3`

PHRASE=`echo $RESULT | cut -d : -f 2`

echo "Username: $UNAME, Line with bad word found: $PHRASE, and Path and file name: $FLOC."


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Northeast Wisconsin Techical College, Green Bay, WI – Joe Cicero – UNIX I

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Kill an specific process ID using the KILL and GREP commands

By enriquegm82

Good afternoon

I need to KILL a process in a single command sentence, for example:

Code:

kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'`


That sentence Kills the process ID corresponding to the program CAL255.4ge.

However it is possible that the same program CAL255.4ge is executed by 2 different users ID, for example:

Code:

/nfs/nfs3/fuentes/per>bgr
Procesos ejecutandose en este momento
-------------------------------------
usuario id hora proceso cola code inst
wilruiz0 401506 16:13:07 CAL224.4ge 203 Vid
wilruiz0 770282 16:16:49 CAL227.4ge 203 Gen
wilruiz0 880676 16:16:51 CAL255.4ge 203 Gen
wilruiz0 995572 16:16:47 CAL224.4ge 203 Gen
wilruiz0 1122314 16:16:37 CAL271.4ge 203 Gen
wilruiz0 1224878 16:13:10 CAL227.4ge 203 Vid
/nfs/nfs3/fuentes/per>ps -aef | grep wilruiz2
wilruiz2 385238 1204422 0 12:37:59 pts/28 0:00 -ksh
wilruiz2 401506 1 6 16:13:07 pts/28 0:05 CAL224.4ge 92793345 203
wilruiz2 880696 1 7 16:16:51 pts/11 0:01 CAL255.4ge 92793345 203
wilruiz2 634998 1073300 0 16:12:58 pts/28 0:00 CAR_main.4ge
wilruiz2 1073300 385238 0 16:12:43 pts/28 0:00 INSUNIX.4ge
wilruiz2 1224878 1 3 16:13:10 pts/28 0:03 CAL227.4ge 92793345 203
/nfs/nfs3/fuentes/per>ps -aef | grep wilruiz0
wilruiz0 602116 733346 1 16:27:54 pts/11 0:00 grep wilruiz0
wilruiz0 733346 798882 1 12:37:33 pts/11 0:00 -ksh
wilruiz0 770282 ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums

GREP for sorting

By siya@

Hi ,

I have a file which has a large number of sequences of type:

gi_1
AASSKSKSKSSKSKSK….
series_121
DDKFKFKGKGKH
gi_3
FFFFLFFLFLFLF
series_1
DFFFFFF
pattern_3
GEEEEEEEEE
gi_2
HKKGGKGKGK
series_102
HHHHH
pattern_1
HHHHH

In order to list all the sequences under gi I do
grep “gi” filename>outputfile
it gives me list of all gi .

However I want to list all of the sequences as shown below.I want to basically know the order like gi_1 followed by series_1 and by gi_3

gi_1
series_121
gi_3
series_1
pattern_3
gi_2
series_102
pattern_1

Is it possible to get all this in a single file and that too in the order they appear in file?

Should i do a multiple grep command to get all these names in a single file to get the order.

Thanks
Sia

Source: FULL ARTICLE at The UNIX and Linux Forums

Using find and regular expressions

By tinku981Hi

Could you please advise how can one extract from the output of
find . -name “*.c” -print
only filenames in the current direcotry and not in its subdirectories?

I tried using (on Linux x86_64)
find . -name “*.c” -prune
but it is not giving correct output.

Whereas I am getting following output

./file1.c
./child_dir/file1.c
./child_dir/file4.c
./child_dir/file2.c
./child_dir/file3.c
./file4.c
./file2.c
./file3.c

Other than prune, is it possible to pipe GREP with find to get desired output?
Source: The UNIX and Linux Forums