Sponsored Content
Top Forums Shell Programming and Scripting Copy of array by index value fails Post 303012768 by RudiC on Thursday 8th of February 2018 04:36:04 PM
Old 02-08-2018
Now this is a problem spec difficult to understand, and I'm not sure I did. Nevertheless, this "proof of concept" worked on a two record file created from your sample. It requires a recent bash (don't run with your above shebang!), and it assumes replacements in every record. Should that not be the case, additional logics is required. The cats are NOT "uuoc"s but are needed for line numbering for later sorting. Be careful with the distinction between <TAB>s and spaces! Give it a try and come back with results...

Code:
prefix=015_
name_tag=CompoundName
sub_tag=Identifier
mapfile < <(cat -n input_file | grep -A1 "^ *1	\|$name_tag\|$sub_tag\|\$\$\$\$" | grep -v "$name_tag\|$sub_tag\|\$\$\$\$\|--\|^ *2	") REP
for ((i=0; i<${#REP[@]}; i+=3))
  do	REP[i+1]="${REP[i+1]%%	*}	PubChem_CID_${REP[i+2]#*	}"
	REP[i]="${REP[i]%%	*}	${prefix}${REP[i+1]#*	}"
	unset REP[i+2]
  done
PAT=${REP[@]%%	*}
PAT="^ *\(${PAT// /\\|}\)	"
sort -k1,1n  <(echo "${REP[@]}") <(cat -n input_file | grep -v "$PAT") | cut -f2-


Last edited by RudiC; 02-08-2018 at 05:42 PM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

2. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

3. Shell Programming and Scripting

Problem when assign the array with the string index

I come across the problems when assigning the array in the script below . How to use the array with the 'string index' correctly ? When I assign a new string index , the array elements that are previously assigned are all changed .:eek::eek::eek: $ array=211 $ echo ${array} 211 $... (4 Replies)
Discussion started by: youareapkman
4 Replies

4. UNIX for Advanced & Expert Users

sql variable as array index

hi folks i am facing problom while trying to access sql variable as array index ina unix shell script....script goes as below.. #!/bin/ksh MAX=3 for elem in alpha beeta gaama do arr=$elem ((x=x+1)) Done SQL_SERVER='servername' /apps/sun5/utils/sqsh -S $SQL_SERVER -U user -P pwd -b -h... (1 Reply)
Discussion started by: sudheer157
1 Replies

5. Shell Programming and Scripting

awk array index help

$ cat file.txt A|X|20 A|Y|20 A|X|30 A|Z|20 B|X|10 A|Y|40 Summing up $NF based on first 2 fields, $ awk -F "|" 'BEGIN {OFS="|"} { sum += $NF } END { for (f in sum) print f,sum } ' file.txt o/p: A|X|50 A|Y|60 A|Z|20 (4 Replies)
Discussion started by: uwork72
4 Replies

6. Shell Programming and Scripting

dynamic index for array in while loop

Hi, I'm just trying to use a dynamic index for some array elements that I'm accessing within a loop. Specifically, I want to access an array at variable position $counter and then also at location $counter + 1 and $counter + 2 (the second and third array positions after it) but I keep getting... (0 Replies)
Discussion started by: weak_code-fu
0 Replies

7. Shell Programming and Scripting

how to search array and print index in ksh

Hi, I am using KSH shell to do some programming. I want to search array and print index value of the array. Example.. nodeval4workflow="DESCRIPTION ="" ISENABLED ="YES" ISVALID ="YES" NAME="TESTVALIDATION" set -A strwfVar $nodeval4workflow strwfVar=DESCRIPTION=""... (1 Reply)
Discussion started by: tmalik79
1 Replies

8. Shell Programming and Scripting

build array name based on loop index

Hi, I am new to perl and I have the following query please help here. I have following array variables declaration @pld1 = qw(00 01 02 03 04 05); @pld2 = qw(10 11 12 13 14 15); for(my $k=1;$k<=2;$k++) { //I want here to use @pld1 if $k is 1 // and @pld2 if $k is 2. How to do... (3 Replies)
Discussion started by: janavan
3 Replies

9. Shell Programming and Scripting

Index problem in associate array in awk

I am trying to reformat the table by filling any missing rows. The final table will have consecutive IDs in the first column. My problem is the index of the associate array in the awk script. infile: S01 36407 53706 88540 S02 69343 87098 87316 S03 50133 59721 107923... (4 Replies)
Discussion started by: yifangt
4 Replies

10. Shell Programming and Scripting

Associative array index question

I am trying to assign indexes to an associative array in a for loop but I have to use an eval command to make it work, this doesn't seem correct I don't have to do this with regular arrays For example, the following assignment fails without the eval command: #! /bin/bash read -d "\0" -a... (19 Replies)
Discussion started by: Riker1204
19 Replies
Net::DNS::RR(3) 					User Contributed Perl Documentation					   Net::DNS::RR(3)

NAME
Net::DNS::RR - DNS Resource Record class SYNOPSIS
"use Net::DNS::RR" DESCRIPTION
"Net::DNS::RR" is the base class for DNS Resource Record (RR) objects. See also the manual pages for each RR type. METHODS
WARNING!!! Don't assume the RR objects you receive from a query are of a particular type -- always check an object's type before calling any of its methods. If you call an unknown method, you'll get a nasty warning message and "Net::DNS::RR" will return "undef" to the caller. new (from string) $a = Net::DNS::RR->new("foo.example.com. 86400 A 10.1.2.3"); $mx = Net::DNS::RR->new("example.com. 7200 MX 10 mailhost.example.com."); $cname = Net::DNS::RR->new("www.example.com 300 IN CNAME www1.example.com"); $txt = Net::DNS::RR->new('baz.example.com 3600 HS TXT "text record"'); Returns a "Net::DNS::RR" object of the appropriate type and initialized from the string passed by the user. The format of the string is that used in zone files, and is compatible with the string returned by "Net::DNS::RR->string". The name and RR type are required; all other information is optional. If omitted, the TTL defaults to 0 and the RR class defaults to IN. Omitting the optional fields is useful for creating the empty RDATA sections required for certain dynamic update operations. See the "Net::DNS::Update" manual page for additional examples. All names must be fully qualified. The trailing dot (.) is optional. new (from hash) $rr = Net::DNS::RR->new( name => "foo.example.com", ttl => 86400, class => "IN", type => "A", address => "10.1.2.3", ); $rr = Net::DNS::RR->new( name => "foo.example.com", type => "A", ); Returns an RR object of the appropriate type, or a "Net::DNS::RR" object if the type isn't implemented. See the manual pages for each RR type to see what fields the type requires. The "Name" and "Type" fields are required; all others are optional. If omitted, "TTL" defaults to 0 and "Class" defaults to IN. Omitting the optional fields is useful for creating the empty RDATA sections required for certain dynamic update operations. The fields are case-insensitive, but starting each with uppercase is recommended. parse ($rrobj, $offset) = Net::DNS::RR->parse($data, $offset); Parses a DNS resource record at the specified location within a DNS packet. The first argument is a reference to the packet data. The second argument is the offset within the packet where the resource record begins. Returns a Net::DNS::RR object and the offset of the next location in the packet. Parsing is aborted if the object could not be created (e.g., corrupt or insufficient data). print $rr->print; Prints the record to the standard output. Calls the string method to get the RR's string representation. string print $rr->string, " "; Returns a string representation of the RR. Calls the rdatastr method to get the RR-specific data. Domain names arereturned in RFC1035 format, i.e. all non letter, digit, hyphen characters are represented as DDD. Besides, all domain names are expanded to fully qualified domain names, with trailing dot. This is in contrast to accessor methods of individual data elements in RR objects, like name, which will not return the trailing dot. rdatastr $s = $rr->rdatastr; Returns a string containing RR-specific data. Subclasses will need to implement this method. name $name = $rr->name; Returns the record's domain name. type $type = $rr->type; Returns the record's type. class $class = $rr->class; Returns the record's class. ttl $ttl = $rr->ttl; Returns the record's time-to-live (TTL). rdlength $rdlength = $rr->rdlength; Returns the length of the record's data section. rdata $rdata = $rr->rdata Returns the record's data section as binary data. Sorting of RR arrays As of version 0.55 there is functionality to help you sort RR arrays. The sorting is done by Net::DNS::rrsort(), see the Net::DNS documentation. This package provides class methods to set the sorting functions used for a particular RR based on a particular attribute. set_rrsort_func Net::DNS::RR::SRV->set_rrsort_func("priority", sub { my ($a,$b)=($Net::DNS::a,$Net::DNS::b); $a->priority <=> $b->priority || $b->weight <=> $a->weight } Net::DNS::RR::SRV->set_rrsort_func("default_sort", sub { my ($a,$b)=($Net::DNS::a,$Net::DNS::b); $a->priority <=> $b->priority || $b->weight <=> $a->weight } set_rrsort_func needs to be called as a class method. The first argument is the attribute name on which the sorting will need to take place. If you specify "default_sort" than that is the sort algorithm that will be used in the case that rrsort() is called without an RR attribute as argument. The second argument is a reference to a function that uses the variables $a and $b global to the "from Net::DNS"(!!)package for the sorting. During the sorting $a and $b will contain references to objects from the class you called the set_prop_sort from. In other words, you can rest assured that the above sorting function will only get Net::DNS::RR::SRV objects. The above example is the sorting function that actually is implemented in SRV. BUGS
This version of "Net::DNS::RR" does little sanity checking on user-created RR objects. COPYRIGHT
Copyright (c) 1997-2002 Michael Fuhr. Portions Copyright (c) 2002-2004 Chris Reinhardt. Portions Copyright (c) 2005-2007 Olaf Kolkman Portions Copyright (c) 2007 Dick Franks All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. EDNS0 extensions by Olaf Kolkman. SEE ALSO
perl(1), Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Update, Net::DNS::Header, Net::DNS::Question, RFC 1035 Section 4.1.3 perl v5.12.1 2009-12-30 Net::DNS::RR(3)
All times are GMT -4. The time now is 11:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy