Sponsored Content
Top Forums UNIX for Dummies Questions & Answers String search - Command to find second occurance Post 302149587 by jim mcnamara on Thursday 6th of December 2007 03:59:57 PM
Old 12-06-2007
Other than looping or using awk, perl, or python, I have no other idea except an extreme hack like this:

Code:
#!/bin/ksh

# total line in file
wc -l inputfile | read filelen dummy

# find the line to start reading on
grep -n 'some string' inputfile | head -n 2 | tail -n 1 | read startline dummy

# subtract start line from total 
length=$(( $filelen - $startline ))

# tail the lines you need.
tail -n $length inputfile

If you are running this against a large file it will waste considerable resources.
It wastes resources anyway, because it reads thru the file several times.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies

2. UNIX for Dummies Questions & Answers

search for a word and it's occurance at the output

hey to everybody this is my first post at this forum I need a very immediate answer for this question. If you can, I will be delightfull I have a file called example.txt and I want to seek for the for hello and learn the number of the occurance of hello (2 Replies)
Discussion started by: legendofanatoli
2 Replies

3. Shell Programming and Scripting

search and replace the last occurance of a match in a file

HI please let me know if there is any command to search and replace only the last occurence of a string in aline. Eg: " This cat is a cat with a tail longer of all cat." I need to replace only the last "cat" in the above line. thanks (3 Replies)
Discussion started by: harikris614
3 Replies

4. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

5. Shell Programming and Scripting

Search and replace only the first occurance

Hi, I need to search a string and replace with nothing, but only the First occurring string using sed/perl/awk (3 Replies)
Discussion started by: suraj.sheikh
3 Replies

6. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

7. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

8. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

9. Shell Programming and Scripting

[Need help] perl script to find the occurance of string from a text file

I have two files 1. input.txt 2. keyword.txt input.txt has contents like .src_ref 0 "call.s" 24 first 0x000000 0x5a80 0x0060 BRA.l 0x60 .src_ref 0 "call.s" 30 first 0x000002 0x1bc5 RETI .src_ref 0 "call.s" 31 first 0x000003 0x6840 ... (2 Replies)
Discussion started by: acdc
2 Replies

10. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies
TCA_CORRECT(1)							       HUGIN							    TCA_CORRECT(1)

NAME
tca_correct - Calculate transverse chromatic aberration SYNOPSIS
tca_correct [options] inputfile <inputfile> is the base name of 4 image files: <inputfile> Colour file to compute TCA parameters red_<inputfile> Red channel of <inputfile> green_<inputfile> Green channel of <inputfile> blue_<inputfile> Blue channel of <inputfile> The channel images must be colour images with 3 identical channels. If any of -R, -G, or -B is given, this file name is used instead of the derived name. Output: commandline arguments for fulla DESCRIPTION
Generates fulla command-line parameters for correction of transverse chromatic aberration (TCA) from sample photos. Ideal sample photos would have a lot of contrast over the entire image area, little saturated colour and no blown highlights. OPTIONS
-h Display help -l input file is PTO file instead of image -m method optimization method (0 normal, 1 newfit) -o optvars string of variables to optimize ("abcvde") -r Reset values (this will zero a,b,c,d,e params and set v to 10) makes sense only with -l option -s <scale> Scale for corner detection -n <number> number of points per grid cell (default: 10) -g <number> divide image in <number>x<number> grid cells (default: 10) -t num Remove all control points with an error higher than num pixels (default: 1.5) -v Verbose -w filename write PTO file -R <r> Use this file as red channel -G <g> Use this file as green channel -B <b> Use this file as blue channel AUTHORS
Written by Pablo d'Angelo and others. "Version: 2011.4.0" 2011-12-02 TCA_CORRECT(1)
All times are GMT -4. The time now is 05:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy