Sponsored Content
Full Discussion: sed in awk ? or nested awk ?
Top Forums UNIX for Advanced & Expert Users sed in awk ? or nested awk ? Post 302162868 by varungupta on Wednesday 30th of January 2008 11:43:10 AM
Old 01-30-2008
PHP Issue still lies ...

Quote:
Originally Posted by fpmurphy
Code:
$ fpm=`awk '$2=="174"  { print $3 }' tempfind.txt` | sed -n /$fpm/p tempfind.txt
t2589vg 8888 11234 -ksh
mqsiadm 174 8888 -ksh
$

Hey murphy,

Thnks for the reply firstof all.

Below is my script :
where i am using your given code..and somehow its not giving desired o/p.
can you please tell me what is wrong in this...

-----------------------------------------------------------------------

#SCRIPT TO CHECK WHO HAS ACCESSED THE LOG/FILE IN PAST 'N' MINUTES, AND MAIL ACCORDINGLY.

MYPATH="/clocal/mqbrkrs/user/mqsiadm/sanjay/"
MAIL_RECIPIENTS="vg517@dcx.com"
Subject=":: File(s) accessed/touched in last few minutes ::"
>tempmail.txt
>tempfind.txt
>filterfile.txt
>tempgrep.txt
#*************************************************************************************************** ****************************************************
## List all the files which one accessed since last 1 min #####
#*************************************************************************************************** *****************************************************


ps -ef | grep "\-ksh" | awk '$8 !~ /grep/ { printf "%s %s %s %s %s\n", $1, $2, $3, $5, $8 ; }' >> ./tempfind.txt

for file_dir in `find $MYPATH -amin -1`
do

echo `fuser -uf "$file_dir" ` >> temp.txt.$$
echo " $file_dir is being accessed" >> temp.txt.$$
done

sed -n '/^[ ][a-z]*/p' temp.txt.$$ >> tempmail.txt
echo "Accessed By: " >>tempmail.txt
sed -n '/^[0-9]/p' temp.txt.$$ > filterfile.txt

for pid_var in `awk '{ print $2 }' filterfile.txt`
do
fpm=`awk '$2=="$pid_var" {print $3}' tempfind.txt` | sed -n '/$fpm/p' tempfind.txt >> tempmail.txt

done

cat tempmail.txt | mailx -s "$Subject" "$MAIL_RECIPIENTS"


-----------------------------------------------------------------------

Its not giving anyting, I tried on commands prompt aswell.
Could you guide me, please.

Thanks
Varun.Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk 2 delimiter nested

Hello All, This work could be very easy for you guys. I would really appreciate help. input file: output file: (Desired) What I am capable of doing: Command: cat inputfile | awk -F\| '{print "num="$1" value="$2" digits="$3" name1="$4" file="$5" code="$6}' > outputfile Result what I am... (5 Replies)
Discussion started by: onlyroshni
5 Replies

2. Shell Programming and Scripting

Awk Script: Nested search using different patter

Hi Friends. Please have a look at dummy file. I need to extract from this file: 1. Counts of event= 2. the 2nd coulmn is unique call id of this transaction. Based on that, i have to search for txstatus= . Note: Values of event, calltype and txstatus can be anything. I want to print... (1 Reply)
Discussion started by: itsmesanju
1 Replies

3. Shell Programming and Scripting

syntax question in regards to nested awk statements

Hello all, I am writing up an input file and I was hoping I could get some guidance as to how to best consolidate these 2 awk statements for 1 while loop. Here's my input file # cat databases.lst #NOTE: These entries are delimited by tabs "\t" #oracleSID name/pass # db11 ... (2 Replies)
Discussion started by: Keepcase
2 Replies

4. Shell Programming and Scripting

Nested case inside awk

please let me know if the below code could be written efficiently inside single awk case "$INP" in ksh) cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}' ;; pset) cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}' ;; dml) cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

5. Shell Programming and Scripting

Help with nested $s and quotations in bash / awk

Folks - newbie bash coder here and I'd like to get your help to make the code below work. As you can see, I was trying to count the total number of lines with the 3rd value >= 15 in a file and wanted to make the threshold "15" configurable, but apparently the $THRESHOLD value was not populated... (3 Replies)
Discussion started by: bashzipper
3 Replies

6. Shell Programming and Scripting

Nested awk Statements

Hello again everyone, yes, I'm back again for more help! So I'm attempting to read two separate files and generate some XML code from that. My current code is: BEGIN { print "<?xml version=\"1.0\" encoding=\"utf-8\">" print "<Export>" } { x=1; print "<section name=\"Query" NR "\">"... (5 Replies)
Discussion started by: Parrakarry
5 Replies

7. Shell Programming and Scripting

Nested if not working with /usr/xpg4/bin/awk

Hi, I am trying to do if inside the If in /usr/xpg4/bin/awk. But I am getting below error : /usr/xpg4/bin/awk -v a="${THREADIDARR }" 'BEGIN {FS="|"; n=split(a,b," "); for(i=1; i<=n; i++) c]=1;} length($3) == 0{ftag == 1{{print}}; length($3) != 0{$3 in c{ftag=1;print;} !$3 in c{ftag=0;}}'... (4 Replies)
Discussion started by: nes
4 Replies

8. Shell Programming and Scripting

How to add second variable in awk nested if condition?

Hi Gurus, I have a command to assign value based on input value. current condition is "if pattern matches "case", then assign "HOLD" else "SUCC"right now, I need to add one more condition (variable name is VAR). the condition is "if pattern1 matches "case", then assign "HOLD" else if... (2 Replies)
Discussion started by: ken6503
2 Replies

9. Shell Programming and Scripting

awk nested looping?

I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk. The text file has a organization like so: Name Date Status Location (city, state, zip fields) Where each of these is on a separate line in... (1 Reply)
Discussion started by: kellyanneghj
1 Replies

10. Shell Programming and Scripting

awk - multiple and nested if-then-else

Hello. I would like to convert the following piece of code from bash to awk. Here are bash variables in a bash script. CUR_ROW_ID and ROW_ID_TO_SEARCH contains a string which represent a row id. The string contain a valid row id. CUR_ROW_ID sometimes may be null. CUR_VALUE... (3 Replies)
Discussion started by: jcdole
3 Replies
regex(1F)                                                          FMLI Commands                                                         regex(1F)

NAME
regex - match patterns against a string SYNOPSIS
regex [-e] [ -v "string"] [ pattern template] ... pattern [template] DESCRIPTION
The regex command takes a string from the standard input, and a list of pattern / template pairs, and runs regex() to compare the string against each pattern until there is a match. When a match occurs, regex writes the corresponding template to the standard output and returns TRUE. The last (or only) pattern does not need a template. If that is the pattern that matches the string, the function simply returns TRUE. If no match is found, regex returns FALSE. The argument pattern is a regular expression of the form described in regex(). In most cases, pattern should be enclosed in single quotes to turn off special meanings of characters. Note that only the final pattern in the list may lack a template. The argument template may contain the strings $m0 through $m9, which will be expanded to the part of pattern enclosed in ( ... )$0 through ( ... )$9 constructs (see examples below). Note that if you use this feature, you must be sure to enclose template in single quotes so that FMLI does not expand $m0 through $m9 at parse time. This feature gives regex much of the power of cut(1), paste(1), and grep(1), and some of the capabilities of sed(1). If there is no template, the default is $m0$m1$m2$m3$m4$m5$m6$m7$m8$m9. OPTIONS
The following options are supported: -e Evaluates the corresponding template and writes the result to the standard output. -v "string" Uses string instead of the standard input to match against patterns. EXAMPLES
Example 1: Cutting letters out of a string To cut the 4th through 8th letters out of a string (this example will output strin and return TRUE): `regex -v "my string is nice" '^.{3}(.{5})$0' '$m0'` Example 2: Validating input in a form In a form, to validate input to field 5 as an integer: valid=`regex -v "$F5" '^[0-9]+$'` Example 3: Translating an environment variable in a form In a form, to translate an environment variable which contains one of the numbers 1, 2, 3, 4, 5 to the letters a, b, c, d, e: value=`regex -v "$VAR1" 1 a 2 b 3 c 4 d 5 e '.*' 'Error'` Note the use of the pattern '.*' to mean "anything else". Example 4: Using backquoted expressions In the example below, all three lines constitute a single backquoted expression. This expression, by itself, could be put in a menu defini- tion file. Since backquoted expressions are expanded as they are parsed, and output from a backquoted expression (the cat command, in this example) becomes part of the definition file being parsed, this expression would read /etc/passwd and make a dynamic menu of all the login ids on the system. `cat /etc/passwd | regex '^([^:]*)$0.*$' ' name=$m0 action=`message "$m0 is a user"`'` DIAGNOSTICS
If none of the patterns match, regex returns FALSE, otherwise TRUE. NOTES
Patterns and templates must often be enclosed in single quotes to turn off the special meanings of characters. Especially if you use the $m0 through $m9 variables in the template, since FMLI will expand the variables (usually to "") before regex even sees them. Single characters in character classes (inside []) must be listed before character ranges, otherwise they will not be recognized. For exam- ple, [a-zA-Z_/] will not find underscores (_) or slashes (/), but [_/a-zA-Z] will. The regular expressions accepted by regcmp differ slightly from other utilities (that is, sed, grep, awk, ed, and so forth). regex with the -e option forces subsequent commands to be ignored. In other words, if a backquoted statement appears as follows: `regex -e ...; command1; command2` command1 and command2 would never be executed. However, dividing the expression into two: `regex -e ...``command1; command2` would yield the desired result. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
awk(1), cut(1), grep(1), paste(1), sed(1), regcmp(3C), attributes(5) SunOS 5.10 12 Jul 1999 regex(1F)
All times are GMT -4. The time now is 05:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy