Sponsored Content
Top Forums Shell Programming and Scripting find string nth occurrence in file and print line number Post 302562324 by Chubler_XL on Thursday 6th of October 2011 02:03:15 PM
Old 10-06-2011
How about this, (produces 1.out, 2.out etc.)

Code:
sed -n '/<SESSION>/,/<\/SESSION>/p' infile | awk ' NF { print $0 RS > ++j ".out" } ' RS='</SESSION>'

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding nth occurrence in line and replacing it

Hi, I have several files with data that have to be imported to a database. These files contain records with separator characters. Some records are corrupt (2 separators are missing) and I need to correct them prior to importing them into the db. Example: ... (5 Replies)
Discussion started by: stresing
5 Replies

2. Programming

Find and print number after string in C

I'm trying find and print a number after a specific user passed string in each line of a text file using C (as requested by the powers that be). I've pieced together enough to read the file, find the string and print the line it was found on but I’m not sure where to even start in terms of finding... (3 Replies)
Discussion started by: cgol
3 Replies

3. Shell Programming and Scripting

how to find third(nth) word in all line from a file

For example i'm having the below contents in a file: expr is great when you want to split a string into just two parts. The .* also makes expr good for skipping a variable number of words when you don't know how many words a string will have. But expr is lousy for getting, say, the fourth word... (2 Replies)
Discussion started by: bangarukannan
2 Replies

4. Shell Programming and Scripting

How to output all lines following Nth occurrence of string

Greetings experts. Searched the forums (perhaps not hard enough?) - Am searching for a method to capture all output from a log file following the nth occurrence of a known string. Background: Using bash, I want to monitor my Oracle DB alert log file. The script will count the total # of... (2 Replies)
Discussion started by: cjtravis
2 Replies

5. Shell Programming and Scripting

Count number of occurrence of a string in file

if there's a file containing: money king money queen money cat money also money king all those strings are on one line in the file. how can i find out how many times "money king" shows up in the line? egrep -c "money king" wont work. (7 Replies)
Discussion started by: SkySmart
7 Replies

6. Shell Programming and Scripting

Find a string occurrence if twice in a line

Hello All, I want to check if a delimiter is existing twice in a line of a text file. Suppose flat file is like this 234 | 123 123 | 345 456 | 563 | 234 | 548 So the the 3rd line has two delimiters, How can we find the lines in such a file having more then one delimiters I tried... (5 Replies)
Discussion started by: nnani
5 Replies

7. Shell Programming and Scripting

Print nth line in a file

Bash/Oracle Linux 6.4 A basic requirement. How can I get nth line of a file printed ? Can I use grep in this case ? Example: In the below file, 12th line is "Kernel parameter check passed for rmem_max" . I just want the 12 line to be printed. # cat sometext.txt Kernel version check... (2 Replies)
Discussion started by: John K
2 Replies

8. Shell Programming and Scripting

How to insert file contents after nth occurrence of a string using sed?

Hi, I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g. > cat file1 banana apple orange apple banana pear tangerine apple > cat file2 I don't like apples What would be the sed command to insert... (5 Replies)
Discussion started by: dimocn
5 Replies

9. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

10. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
MB_STRISTR(3)								 1							     MB_STRISTR(3)

mb_stristr - Finds first occurrence of a string within another, case insensitive

SYNOPSIS
string mb_stristr (string $haystack, string $needle, [bool $before_needle = false], [string $encoding = mb_internal_encoding()]) DESCRIPTION
mb_stristr(3) finds the first occurrence of $needle in $haystack and returns the portion of $haystack. Unlike mb_strstr(3), mb_stristr(3) is case-insensitive. If $needle is not found, it returns FALSE. PARAMETERS
o $haystack - The string from which to get the first occurrence of $needle o $needle - The string to find in $haystack o $before_needle - Determines which portion of $haystack this function returns. If set to TRUE, it returns all of $haystack from the beginning to the first occurrence of $needle (excluding needle). If set to FALSE, it returns all of $haystack from the first occurrence of $needle to the end (including needle). o $encoding - Character encoding name to use. If it is omitted, internal character encoding is used. RETURN VALUES
Returns the portion of $haystack, or FALSE if $needle is not found. SEE ALSO
stristr(3), strstr(3), mb_strstr(3). PHP Documentation Group MB_STRISTR(3)
All times are GMT -4. The time now is 09:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy