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
Mail(3pm)						User Contributed Perl Documentation						 Mail(3pm)

NAME
Palm::Mail - Handler for Palm Mail databases. SYNOPSIS
use Palm::Mail; DESCRIPTION
The Mail PDB handler is a helper class for the Palm::PDB package. It parses Mail databases. AppInfo block The AppInfo block begins with standard category support. See Palm::StdAppInfo for details. Other fields include: $pdb->{appinfo}{sortOrder} $pdb->{appinfo}{unsent} $pdb->{appinfo}{sigOffset} I don't know what these are. Sort block $pdb->{sort} This is a scalar, the raw data of the sort block. Records $record = $pdb->{records}[N] $record->{year} $record->{month} $record->{day} $record->{hour} $record->{minute} The message's timestamp. $record->{is_read} This is defined and true iff the message has been read. $record->{has_signature} For outgoing messages, this is defined and true iff the message should have a signature attached. The signature itself is stored in the "Saved Preferences.prc" database, and is of type "mail" with ID 2. $record->{confirm_read} If this is defined and true, then the sender requests notification when the message has been read. $record->{confirm_delivery} If this is defined and true, then the sender requests notification when the message has been delivered. $record->{priority} An integer in the range 0-2, for high, normal, or low priority, respectively. $record->{addressing} An integer in the range 0-2, indicating the addressing type: To, Cc, or Bcc respectively. I don't know what this means. $record->{subject} $record->{from} $record->{to} $record->{cc} $record->{bcc} $record->{replyTo} $record->{sentTo} Strings, the various header fields. $record->{body} A string, the body of the message. METHODS
new $pdb = new Palm::Mail; Create a new PDB, initialized with the various Palm::Mail fields and an empty record list. Use this method if you're creating a Mail PDB from scratch. new_Record $record = $pdb->new_Record; Creates a new Mail record, with blank values for all of the fields. "new_Record" does not add the new record to $pdb. For that, you want "$pdb->append_Record". Note: the time given by the "year", "month", "day", "hour", and "minute" fields in the new record are initialized to the time when the record was created. They should be reset to the time when the message was sent. SOURCE CONTROL
The source is in Github: http://github.com/briandfoy/p5-Palm/tree/master AUTHOR
Alessandro Zummo, "<a.zummo@towertech.it>" Currently maintained by brian d foy, "<bdfoy@cpan.org>" SEE ALSO
Palm::PDB(3) Palm::StdAppInfo(3) perl v5.10.1 2010-02-23 Mail(3pm)
All times are GMT -4. The time now is 02:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy