Sponsored Content
Top Forums Shell Programming and Scripting Better and efficient way to reverse search a file for first matched line number. Post 302562435 by ahamed101 on Thursday 6th of October 2011 11:42:43 PM
Old 10-07-2011
what is the output you are expecting?

--ahamed

---------- Post updated at 08:37 PM ---------- Previous update was at 08:24 PM ----------

This will print the first occurence from last i.e. output = 4
Code:
awk '{a[++i]=$0} END{for(j=i;j>0;j--){if(a[j] ~ "Started"){print j;j=0}}}' input_file

Looks like you are in solaris. Use nawk.

--ahamed

---------- Post updated at 08:42 PM ---------- Previous update was at 08:37 PM ----------

or

Code:
grep -n  Started input_file | tail -1 | cut -f1 -d":"

or

Code:
grep -n  Started input_file | sed -n '{s/\([0-9]\).*/\1/g;$p}'

--ahamed
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search for the matched pattern by tracing back from the line

Hi, I want to grep the line which has 'data11'.then from that line, i need to trace back and find out the immediate line which has the same timestamp of that grepped line. for eg: log file: ----------- Process - data Process - datavalue - 2345 Process - data Process - data Process... (9 Replies)
Discussion started by: Sharmila_P
9 Replies

2. Shell Programming and Scripting

reverse search a text file from a specified line

Hello All, I have a following task that I need to accomplish through a script or program and I am looking for some help as I have exhausted my ideas. 1. given: a text file with thousands of lines 2. find: pattern A in file and get line number ( grep -n works) 3. find: the first occurence of... (14 Replies)
Discussion started by: PacificWonder
14 Replies

3. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

4. Shell Programming and Scripting

Match a line in File 1 with Column in File 2 and print whole line in file 2 when matched

Hi Experts, I am very new to scripting and have a prb since few days and it is urgent to solve so much appreciated if u help me. i have 2 files file1.txt 9647810043118 9647810043126 9647810043155 9647810043161 9647810043166 9647810043185 9647810043200 9647810043203 9647810043250... (22 Replies)
Discussion started by: mustafa.abdulsa
22 Replies

5. Shell Programming and Scripting

how do I break line in a file when a pattern is matched ?

Hi All, I am stuck for quite sometime now. Below is a line in my file - GS|ED|001075|001081|20110626|1806|100803|X|004010ST|130|100803001 This line occurs only once and it is the second line. I have to break this line into two lines from ST (bold) such that it looks like -... (5 Replies)
Discussion started by: ihussain
5 Replies

6. Shell Programming and Scripting

search a string in a particular column of file and return the line number of the line

Hi All, Can you please guide me to search a string in a particular column of file and return the line number of the line where it was found using awk. As an example : abc.txt 7000,john,2,1,0,1,6 7001,elen,2,2,0,1,7 7002,sami,2,3,0,1,6 7003,mike,1,4,0,2,1 8001,nike,1,5,0,1,8... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

7. Shell Programming and Scripting

Need an efficient way to search for a tag in an xml file having millions of rows

Hi, I have an XML file with around 1 billion rows in it and i am trying to find the number of times a particular tag occurs in it. The solution i am using works but takes a lot of time (~1 hr) .Please help me with an efficient way to do this. Lets say the input file is <Root> ... (13 Replies)
Discussion started by: Sheel
13 Replies

8. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

9. Shell Programming and Scripting

Efficient way to search array in text file by awk

I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will perform below operation.my issue is that it's taking more time because for one number it's search... (6 Replies)
Discussion started by: siramitsharma
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
tcpd.conf(4)						     Kernel Interfaces Manual						      tcpd.conf(4)

NAME
tcpd.conf - configuration file for tcpd DESCRIPTION
When invokes for a service, it will read and perform access control checks (see tcpd(1M)). Each line in the file is treated either as a comment or as configuration information. Commented lines begin with Uncommented lines contain two required fields, key and value. The fields are separated by tabs and/or spaces. A line can be continued if it terminates with a back- slash The following are the configuration parameters: The RFC931 username lookup can be enabled or disabled through this parameter. Value for n specifies the time-out value (in sec- onds), to be used while getting the username information from the client. A value of zero for n disables the rfc931 feature. The default configuration of this disables the rfc931 feature with n value equal to 0. The maximum value to which n can be set is 30 seconds. This parameter determines whether should allow or deny the connection request on reverse lookup failure. In both the cases, will log the event of reverse lookup failure, but in the case, it will reject the connection request just after reverse lookup failure. In the case, the hostname can be matched with the PARANOID wildcard (see hosts_options(5)) in access con- trol files and The default value for this is This parameter determines the level at which should log the information using A value of will cause the TCP Wrappers daemon (see tcpd(1M)), to log the ACLs information such as with which entry the client request is matched and this entry's related options. The default value for this entry is in which case will only log the connection details about refusal or acceptance of the connection in the form of `connection from abc@xyz_host'. Processing Invalid and Multiple Entries processes invalid and multiple entries in the following ways: o An invalid entry for a configuration parameter is ignored. Instead, the default value for the configuration parameter will be used. For example, the following invalid entry for log_level will be replaced by the use of normal. will be treated as: o If multiple entries for a configuration parameter are specified, only the last occurring entry is processed and the rest are ignored. For example, in the following two entries for the last value of 25 is used for that parameter. EXAMPLES
To set the a 25 seconds time-out value for RFC931 user name lookup: To disable the RFC931 user name lookup: To make to allow a host on reverse lookup failure and process that host as in ACLs: To set the extended logging option: AUTHOR
was developed by the Hewlett-Packard. SEE ALSO
inetd(1M), tcpd(1M). tcpd.conf(4)
All times are GMT -4. The time now is 07:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy