ksh script to process grep output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh script to process grep output
# 8  
Old 06-06-2010
Because I'm bored, here is a pure shell solution:

Code:
(19:41:12\[D@DeCoBox15)
[~]$ cat par
#!/bin/ksh

IFS=":"
while read date act ;do
case $act in
"C The user has created a record" )
echo "$date:C"
;;
"U The user has updated a record" )
echo "$date:U"
;;
"D The user has deleted a record" )
echo "$date:D"
;;
*)
echo "$date:Unknown action"
;;
esac
done < $1

(19:41:14\[D@DeCoBox15)
[~]$ cat exp
2010-04-28-11-12-21.txt:C The user has created a record
2010-04-29-10-18-41.txt:U The user has updated a record
2010-04-30-10-19-31.txt:D The user has deleted a record
2010-04-28-11-12-21.txt:O The user has opened a record

(19:41:17\[D@DeCoBox15)
[~]$ ./par exp
2010-04-28-11-12-21.txt:C
2010-04-29-10-18-41.txt:U
2010-04-30-10-19-31.txt:D
2010-04-28-11-12-21.txt:Unknown action

(19:41:20\[D@DeCoBox15)
[~]$

# 9  
Old 06-06-2010
Quote:
Originally Posted by alienated
If I want to print the original line in cases when the letters C,U,D is not found
Code:
awk '!/^[^:]+:[UCD]/ {print; next} {$0=$1} /U$/ {a="pdate"} /C$/ {a="reate"} /D$/ {a="elete"} {print $0a}'



---------- Post updated at 01:42 PM ---------- Previous update was at 01:21 PM ----------

Simpler version of my previous AWK:
Code:
awk '{o=$0; a=""; $0=$1} /U$/ {a="pdate"} /C$/ {a="reate"} /D$/ {a="elete"} {print (a?$0a:o)}'

This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

2. Shell Programming and Scripting

Grep for process in a ksh script

Hi I'm trying to catch a particular process (XYZ) running using a ksh script. Like So.. VarPS=`ps -ef |grep XYZ |grep -v grep` However this seems to find the process of the script itself - not the process 'XYZ' Asked in Error - I found my own typo... thanks anyway Skrynesaver (1 Reply)
Discussion started by: Mudshark
1 Replies

3. Shell Programming and Scripting

ksh script to check if certain process is running

I have to kill the process "test" for a maintenance I do but want the script to check when it comes back up. I can get what I want when I run this while loop: while true;do ps -ef | grep test | grep -v grep | sed -e 's/^*//';sleep 60;done but I want the script to do it for me and as soon as... (6 Replies)
Discussion started by: seekryts15
6 Replies

4. UNIX for Dummies Questions & Answers

ksh script - not getting output from ls

Hi! I'm a complete noob, and I'm trying to write a little script that takes a directory pathname as input from the CL, checks whether it exists, and if not creates it, then shows it worked using ls. Everything works beautifully except in the first instance, wherein the directory is created, ls... (10 Replies)
Discussion started by: sudon't
10 Replies

5. Shell Programming and Scripting

Script in KSH to check if a process its up or down.

Hi all! Im working on a simple script in KSH (just started) to check if a process its up or down, but im kind of lost with the following error. Script: #!/usr/bin/ksh psup=$(ps -ef | grep sftp | egrep -v grep | wc -l) if ($psup > 0); then echo "Process SFTP running" else ... (6 Replies)
Discussion started by: ARSport
6 Replies

6. Shell Programming and Scripting

Help with ksh script to display output with specific contents

This is Input - starts with Storage Group Name and ends with Shareable and the loop continues all I need is Storage group name and Alu numbers in the below output format requested. Storage Group Name: abcd Storage Group UID: 00:00:000:00:0:0:0 HBA/SP Pairs: HBA UID ... (6 Replies)
Discussion started by: maddysa
6 Replies

7. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

8. Shell Programming and Scripting

Ksh Script to get the start minute of n number of process

How can i write a script.? which lists all X process and gets the start minute of each of them. thanks (1 Reply)
Discussion started by: Anteus
1 Replies

9. Shell Programming and Scripting

ksh: cmd output to input of another script

I want to write a script in KSH that takes the output of one command and redisplays it. Something like: while true do read inpt date +"%I:%M:%S %p <-> $inpt" done and then some how get the output of the ping command to redirect to the input of this script. does that make sense? (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

10. Shell Programming and Scripting

script ksh/awk/grep

How can I extract the 9th line of a text file. thanks vm.:confused: (2 Replies)
Discussion started by: hoang
2 Replies
Login or Register to Ask a Question