Match text to lines in a file, iterate backwards until text or text substring matches, print to file
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
i'm trying to take each line in file1 and using the original text to match, if no match, iterate backwards one character at time, until it matches first column in file2, loop through all of file2 and print all matching lines where text and any substring matches the first column of file2 to another file. output file3 essentially will have concatenated output of original text from file1 and matching lines from file2
Hi all,
I have a text file and I want to clean up the file by only print those lines start with the date. Is there anyway I can do that?
Thanks
CT (1 Reply)
Hi,
Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11
Thanks for your help. (6 Replies)
I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it.
For example, Here is a portion of a zone file.
IN NS ns1.domain.tld.
IN NS ns2.domain.tld.
IN ... (2 Replies)
Hi,
I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries.
The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
I dont even have a sample script cause I dont know where to start from. My data lookes like this
> sat#16 #data: 15 site:UNZA baseline: 205.9151
0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722
0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
I'm trying to pull an image source url from a html source file. I'm new with regex. I'm in BaSH. I've tried grep -E 'http.*jpg' file which highlights the text, but gives me 2 problems:
1) Results aren't stand alone and can't be piped to another command. (I believe it includes everything in... (5 Replies)
I hope this makes sense and is possible.
I am trying to match $1 of panel_genes.txt with $3 of RefSeqGene.txt and when a match is found the value in $6 of RefSeqGene.txt
Example: ACTA2 is $1 of panel_genes.txt
ACTA2 NM_001613.2
ACTA2 NM_001141945.1
awk 'FNR==NR {... (4 Replies)
I am trying to remove each line in which $2 is FP or RFP. I believe the below will remove one instance but not both. Thank you :).
file
12
123 FP
11
10 RFP
awk
awk -F'\t' '
$2 != "FP"' file
desired output
12
11 (6 Replies)
In the below file I am trying to grep or similar, all lines where only AF= is less than 0.4.. Thank you :).
grep
grep "AF=" ,+ .4 file
file
12 112036782 . T C 34.0248 PASS ... (3 Replies)
Discussion started by: cmccabe
3 Replies
LEARN ABOUT PHP
substr_count
SUBSTR_COUNT(3) 1 SUBSTR_COUNT(3)substr_count - Count the number of substring occurrencesSYNOPSIS
int substr_count (string $haystack, string $needle, [int $offset], [int $length])
DESCRIPTION substr_count(3) returns the number of times the $needle substring occurs in the $haystack string. Please note that $needle is case sensi-
tive.
Note
This function doesn't count overlapped substrings. See the example below!
PARAMETERS
o $haystack
- The string to search in
o $needle
- The substring to search for
o $offset
- The offset where to start counting
o $length
- The maximum length after the specified offset to search for the substring. It outputs a warning if the offset plus the length is
greater than the $haystack length.
RETURN VALUES
This function returns an integer.
CHANGELOG
+--------+-----------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+-----------------------------------------------+
| 5.1.0 | |
| | |
| | Added the $offset and the $length parameters |
| | |
+--------+-----------------------------------------------+
EXAMPLES
Example #1
A substr_count(3) example
<?php
$text = 'This is a test';
echo strlen($text); // 14
echo substr_count($text, 'is'); // 2
// the string is reduced to 's is a test', so it prints 1
echo substr_count($text, 'is', 3);
// the text is reduced to 's i', so it prints 0
echo substr_count($text, 'is', 3, 3);
// generates a warning because 5+10 > 14
echo substr_count($text, 'is', 5, 10);
// prints only 1, because it doesn't count overlapped substrings
$text2 = 'gcdgcdgcd';
echo substr_count($text2, 'gcdgcd');
?>
SEE ALSO count_chars(3), strpos(3), substr(3), strstr(3).
PHP Documentation Group SUBSTR_COUNT(3)