|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hey all,
Can I put sed command inside the awk action ?? If not then can i do grep in the awk action ?? For ex: awk '$1=="174" { ppid=($2) ; sed -n '/$ppid/p' tempfind.txt ; }' tempfind.txt Assume: 174 is string. Assume: tempfind.txt is used for awk and sed both. tempfind.txt contains : t2589vg 8888 11234 -ksh mqsiadm 128 134 -ksh mqsiadm 174 8888 -ksh Please let me know, its an urgent. Thanks to all brains. You can give your opinion/examples/suggustions regarding the same (to use: sed in awk or grep in awk or nested awk). Varun. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
$ fpm=`awk '$2=="174" { print $3 }' tempfind.txt` | sed -n /$fpm/p tempfind.txt
t2589vg 8888 11234 -ksh
mqsiadm 174 8888 -ksh
$ |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Code:
awk 'BEGIN {
while (getline < "file")
if ($2 == 174)
ppid = $3
} {
if ($0 ~ ppid)
print
}' file |
|
#4
|
|||
|
|||
|
Quote:
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. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Put the sed command inside double ticks as the single ones prevent variable expansion... Code:
sed -n "/$fpm/p" |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
I tried using : fpm=`awk '$2=="966906" {print $3}' tempfind.txt` | sed -n "/$fpm/p" tempfind.txt but still its not working. Whenever I do only awk '$2=="966906" {print $3}' tempfind.txt it works and gives the value of $3, but when we assign $3 to fpm variable, its not going ahead. Even i have tried.. fpm=`awk '$2=="966906" {print $3}' tempfind.txt` | echo "$fpm" It does not show anything. Where is the matter ?? Please suggust me, this is the last thing in my script and am waiting to complete it. Thanks !! Varun Last edited by varungupta; 01-30-2008 at 04:07 PM.. |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Another method of solving the original question using getline Code:
$cat awkfile
BEGIN { pid="" }
$2=="174" { pid=$3 }
END {
if (pid != "") {
tmp="sed -n /"pid"/p file"
while ((tmp | getline) > 0)
print
close(tmp)
}
}
$Code:
$ awk -f awkfile tempfile.txt t2589vg 8888 11234 -ksh mqsiadm 174 8888 -ksh $ |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Nested if in KSH | Calbrenar | Shell Programming and Scripting | 4 | 10-19-2011 03:29 PM |
| KSH nested loops? | mrice | Shell Programming and Scripting | 9 | 07-26-2011 08:17 PM |
| Help nested sql | joje47 | Programming | 1 | 05-31-2011 11:25 AM |
| Nested If statement within Do / Done | dalgibbard | UNIX for Dummies Questions & Answers | 2 | 12-22-2009 10:10 AM |
| awk 2 delimiter nested | onlyroshni | Shell Programming and Scripting | 5 | 10-10-2007 05:01 AM |
|
|