apple X:5_yes_a
apple X:12_no_b
apple X:45_yes_a
apple X:100_no_b
banana X:7_yes_a
banana X:13_yes_a
banana X:42_no_a
cat X:42_no_b
cat X:77_yes_d
I'd like to parse the file so that for each $1 value I return only lines in which the value in $2 after the : and before the "_" is more than 10 greater than the previous value.
e.g.
apple X:5_yes_a
apple X:45_yes_a
apple X:100_no_b
banana X:7_yes_a
banana X:42_no_a
cat X:42_no_b
cat X:77_yes_d
So for each new $1 I'd like to print the line and then for each identical $1 I'd like to only print the line if the substring value in $2 between ":" and the next "_" for line X+1 - line X is > 10.
Sure,
first split the record based on the FS to locate $2:
For each record evaluate the following expression:
The first part is easy, it tests if the current $2 is greater than the previous one + 10 (the variable s is set in the action (s=$2), so when the expression is tested it contains the value of the previous record). !array[string]++ is a common AWK idiom, it returns true when string is matched for the first time, it could be easier to understand like this:
AWK auto-initializes variables as NULL (in string context) or 0 (in numeric context). When it post-increments the associative array for the first time, it's value is 0 (see AWK associative arrays for more info on this). The || operator is logical OR.
Hello.
First best wishes for everybody.
here is the input file ("$INPUT1") contents :
BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY;
BASH_FUNC_message_debug%%=() { local -a L_ARRAY;
BASH_FUNC_message_end_script%%=() { local -a L_ARRAY;
BASH_FUNC_message_error%%=() { local... (3 Replies)
I was looking at this script which outputs the two lines which differs less than one sec.
#!/usr/bin/perl -w
use strict;
use warnings;
use Time::Local;
use constant SEC_MILIC => 1000;
my $file='infile';
## Open for reading argument file.
open my $fh, "<", $file or die "Cannot... (1 Reply)
Hi,
I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the... (2 Replies)
Hi All,
Below is some sample content of my input file:
There are many types and traditions of anarchism, some of which are ]. Strains of anarchism have been divided into the categories of ] and ] or similar dual classifications. Anarchism is often considered to be a radical ] ideology, and... (8 Replies)
Hi
I want to use korn shell.
I have files in a directory of following format
abc01of09xyz
abc02of09mno
aabc03of09qrs
---
--
requirement first is to check if any files of format "abc*of*" exists. If yes then match the number of such files with the number mentioned in each files(09 in... (1 Reply)
Hi All,
Problem Description:
XML_REP_REQUEST=`CONCSUB "$LOGIN" "SQLAP" "$RESP_NAME" "$USRNM" WAIT="Y" "CONCURRENT" "APPLICATION_SHORT_NAME"
"CP_SHORT_NAME"`
echo Report Request: $XML_REP_REQUEST --to print value in log file
While execution the value of 'XML_REP_REQUEST' is 'Prozess... (5 Replies)
hi all,
I am trying to extract SUBSTRINGS out of a string using ksh.
The string is "SAPR3K.FD0.FA.TJ.B0010.T050302"
I tried using
a= `expr substr $stringZ 1 2`
which is giving me a syntax error, donno why??
any ideas why its not working??
I also tried
echo "welcome" | awk '{... (3 Replies)