Sponsored Content
Top Forums Shell Programming and Scripting search for the matched pattern by tracing back from the line Post 302221313 by Sharmila_P on Monday 4th of August 2008 07:57:08 AM
Old 08-04-2008
hi, actually,my need is like,in the given file i have to find the line which has the keyword "Not authenticated by System" and
"authenticated by System".and i have to get the corresponding names which here is 'sharmila' and 'shivu'.
If it is not authenticated i have to make the status as 'Failure' otherwise as 'Success'.
So here In case of 'Not authenticated i can read the name'sharmila' from the same line.But in case of 'authenticated' i have to trace back the line which has the same timestamp.it may be in anyline.here is my code.


for i in $(grep -n "authenticated by System" logfile.txt|cut -d: -f1)
do
sed -n "${i},${i}p" logfile.txt| /usr/xpg4/bin/grep -q "NOT authenticated by System"
if [ $? -eq 0 ]
then
sed -n "${i},${i}p" logfile.txt|cut -d" " -f5 | sed '1s/^.//' | sed '$s/.$//' >> msg.txt
echo "Failure" >> msg.txt

else
sed -n "${i},${i}p" logfile.txt| /usr/xpg4/bin/grep -q "getCredentials"
if [ $? -eq 0 ]
then
sed -n "${i},${i}p" logfile.txt|cut -d" " -f4 >> msg.txt
echo "Success" >> msg.txt
fi

fi
done


so my need is in the else part how i can get that particular mathched line.
As i am new to unix ,i dont know how i can do this using awk.
Can anyone tell me ,whether in the given code i can get that line or how i can apply the awk here.


logfile:
--------
[22/Jul/2008:19:35:45-20401-23-1] getCredentials - sharmila
[22/Jul/2008:19:35:45-20401-23-2] DoLogin - Setting variables
[22/Jul/2008:19:35:45-20401-23-1] DoLogin - data authenticated by System.
[22/Aug/2008:29:37:14-20401-56-1] DoLogin - User 'sharmila' was NOT authenticated by System.
[12/Jan/2008:19:35:45-20401-23-1] getCredentials - shivu
[22/Jul/2008:19:35:45-20401-23-2] DoLogin - Setting varaibles for all
[22/Jul/2008:19:35:45-20401-23-1] DoLogin - User authenticated by System
[22/Aug/2008:29:37:14-20401-56-1] DoLogin - User 'shivu' was NOT authenticated by System.

thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

2. Shell Programming and Scripting

Help required on joining one line above & below to the pattern matched string line.

Hi Experts, Help needed on joining one line above & below to the pattern matched string line. The input file, required output is mentioned below Input file ABCD DEFG5 42.0.1-63.38.31 KKKK iokl IP Connection Available ABCD DEFG5 42.0.1-63.38.31 ... (7 Replies)
Discussion started by: krao
7 Replies

3. Shell Programming and Scripting

Use AWK to move matched line back one?

Can somebody help me with this? I'm sure it's a no-brainer if you know awk... but I don't. Input: Blah Blah Me love you long time Blah Blah awk magic with 'long time' ==> Output: Blah Blah Me love you long time (0 Replies)
Discussion started by: Ryan.
0 Replies

4. Shell Programming and Scripting

Insert certain field of matched pattern line above pattern

Hello every, I am stuck in a problem. I have file like this. I want to add the fifth field of the match pattern line above the lines starting with "# @D". The delimiter is "|" eg > # @D0.00016870300|0.05501020000|12876|12934|3||Qp||Pleistocene||"3 Qp Pleistocene"|Q # @P... (5 Replies)
Discussion started by: jyu3
5 Replies

5. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

6. Shell Programming and Scripting

Search: find current line, then search back

Hello. I want to find a line that has "new = 0" in it, then search back based on field $4 () in the current line, and find the first line that has field $4 and "last fetch" Grep or Awk preferred. Here is what the data looks like: 2013-12-12 12:10:30,117 TRACE last fetch: Thu Dec 12... (7 Replies)
Discussion started by: JimBurns
7 Replies

7. UNIX for Advanced & Expert Users

To print from the first line until pattern is matched

Hi I want to print the line until pattern is matched. I am using below code: sed -n '1,/pattern / p' file It is working fine for me , but its not working for exact match. sed -n '1,/^LAC$/ p' file Input: LACC FEGHRA 0 LACC FACAF 0 LACC DARA 0 LACC TALAC 0 LAC ILACTC 0... (8 Replies)
Discussion started by: Abhisrajput
8 Replies

8. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

9. Shell Programming and Scripting

Search for Pattern as output between the matched String

Hello, I have a file which has the below contents : VG_name LV_name LV_size in MB LV_option LV_mountpoint owner group y testdg rahul2lv 10 "-A y -L" /home/abc2 ... (6 Replies)
Discussion started by: rahul2662
6 Replies

10. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies
X2SYS_MERGE(1gmt)					       Generic Mapping Tools						 X2SYS_MERGE(1gmt)

NAME
x2sys_merge - Merge an updated COEs tables SYNOPSIS
x2sys_merge -Amain_COElist.d -Mnew_COElist.d DESCRIPTION
x2sys_merge will read two crossovers data base and output the contents of the main one updated with the COEs in the second one. The second file should only contain updated COEs relatively to the first one. That is, it MUST NOT contain any new two tracks intersections (This point is NOT checked in the code). This program is useful when, for any good reason like file editing NAV correction or whatever, one had to recompute only the COEs between the edited files and the rest of the database. -A Specify the file main_COElist.d with the main crossover error data base. -M Specify the file new_COElist.d with the newly computed crossover error data base. OPTIONS
No space between the option flag and the associated arguments. EXAMPLES To update the main COE_data.txt with the new COEs estimations saved in the smaller COE_fresh.txt, try x2sys_merge -ACOE_data.txt -MCOE_fresh.txt > COE_updated.txt SEE ALSO
x2sys_binlist(1), x2sys_cross(1), x2sys_datalist(1), x2sys_get(1), x2sys_init(1), x2sys_list(1), x2sys_put(1), x2sys_report(1) GMT 4.5.7 15 Jul 2011 X2SYS_MERGE(1gmt)
All times are GMT -4. The time now is 05:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy