... I have a similar input but this code is not giving any put. may i know why please..
similar but not so similar input
Sure.
It doesn't work because the earlier input file had numeric values for the columns "a1", "a2", "a3", ... etc. and so I had used the numeric comparison operator, shown in red color below -
This time round, the column values are - "a/a", "a/b", "b/b" etc. which are not numeric. Hence the string comparison operator ne should be used instead of !=.
In fact, even after making that change, it won't work because this line:
would simply increment $n if the current element of @y is unequal to the prior element of @y. So, the values would be like so -
Whereas Scrutinizer's script retains the value 1 instead of 3 since "a/a" has been encountered earlier -
Note that the value of the last column ($n) is the same for all values of "I_1:a/a", and it increments if "I_1:a/a" changes to "I_1:a/b". This can be achieved in Perl by keeping "I_1:a/a" as the key of a hash, and the incremented value of $n as the corresponding value.
Here's the modified script with all the ideas incorporated -
If the key of hash %z i.e. "I_1:a/a" or "I_1:a/b" etc. does not exist, then I increment the value of $n (which is reset to 0 at start of every line), and set this at the value of that key and display this value.
Otherwise, I just display the value of the hash key.
Don't hate me scrutinizer. I need a small update.
Consider 1st and 2nd columns as keys and 3rd column as their values.
The recent awk script here is turning all they keys with values ( similar letter pairs 1st occurrence of similar letters as 1 and 2nd occ.. as 3. and if they are diff then as 2 )
(ex: a/a as 1, a/b as 2 and b/b as 3)
Upgrade:
If any key (for ex: I_3-a9 has different letters in c/d name it as always 2. if this different letter pair repeats with another set (ex: c/e) name it with "?". And remaining same letter pairs (first occurrence) a/a and (second..) b/b remains as 1 and 3.
UpgradeOutput:
Last edited by ruby_sgp; 05-24-2010 at 03:45 AM..
Reason: format problem
Hello to all,
I'm trying to print the value corresponding to the words A, B, C, D, E. These words could appear sometimes and sometimes not inside each group of lines. Each group of lines begins with "ZYX".
My issue with current code is that should print values for 3 groups and only is... (6 Replies)
Hi,
Please help to fetch the values for a key from below data format in linux.
Sample Input Data Format
11055005|PurchaseCondition|GiftQuantity|1
11055005|PurchaseCondition|MinimumPurchase|400
11055005|GiftCatalogEntryIdentifier|Id|207328014
11429510|PurchaseCondition|GiftQuantity|1... (2 Replies)
I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but
- Currently, script is not printing lines to File3.txt in order.
Thanks a lot.
Any help is appreciated.
Script I am using:
awk 'FNR == NR && ! /^]*$/ {... (9 Replies)
Hi ,
I am looking to print the whole string from file2.txt but it is only printing 77 but not the whole matched string from File2.txt Any help is appreciated.
Thanks,
Script
awk '
BEGIN {
OFS="\t"
out = "a.txt"}
NR==FNR && NF {a=$0; next}
function print_65_11() {
if... (11 Replies)
value=$(some command)
for all in `echo $value`
do
awk checks each value (all) to see if it is a odd number. if so, prints the value
done
sounds easy enough but i've been unable to find anything on google. (2 Replies)
Hi Experts,
I am trying to get the output from a matching pattern but unable to construct the awk command:
file :
aa bb cc 11
dd aa cc 33
cc 22 45 68
aa 33 44 44
dd aa cc 37
aa 33 44 67
I want the output to be : ( if $1 match to "aa" start of the line,then print $4 of that line, and... (3 Replies)
I have two files... file1 and file2.
Where columns 1 and 2 of file1 match columns 1 and 2 of file2 I want to create a new file that is all file1 + columns 3 and 4 of file2
:b: Many thanks if you know how to do this.... :b:
file1
31-101 106 0 92
31-101 106 29 ... (2 Replies)
Hello,
I have a data file with 300,000 records in it, and another file which contains only the line numbers of roughly 13,000 records in the data file which have data integrity issues. I'm trying to find a way to print the original data by line number identified in the second file. How can I do... (2 Replies)
Dear Guyz:)
I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z).
I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)