Sponsored Content
Top Forums Shell Programming and Scripting Problem getting sed to work with variables Post 303013794 by RudiC on Wednesday 28th of February 2018 12:53:07 PM
Old 02-28-2018
Your code(s) are working for me:
Code:
current_name="${FIELD[1]}"
sed -e "0,/$current_name/s//$new_name/" $base_file 
id    Name
1    methyl-(2-methylpropoxy)-oxoammonium
2    N-amino-N-(methylamino)-2-nitrosoethanamine
3    3-methoxy-3-methyloxazolidin-3-ium
4    1,3-dihydroxypropan-2-yl-methyl-methyleneammonium
5    dup_0_(1R)-1,2,3,3-tetraamino-2-propen-1-ol
6    2-(ethoxyamino)guanidine
7    O-[(2S)-2-aminoazopropyl]hydroxylamine
8    N-$l^{1}-oxidanyl-N-[(2-methylpropan-2-yl)oxy]methanamine
9    (1R)-1,2,3,3-tetraamino-2-propen-1-ol
10    1-amino-1-ethoxyguanidine

One problem might be that your input data do have DOS line terminators (<CR> = 0x0D = ^M = \r); did you try without?

BTW, your approach seems somewhat complicated. Does it do anything else or is its sole purpose to add a counter to the first instance of duplicates?

Last edited by RudiC; 02-28-2018 at 02:07 PM..
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Working with Script variables; seems like this should work...

The following seems quite basic but does not seem to work. Anybody know why? $ g=1 $ echo $g 1 $ echo abc$g abc1 $ abc$g=hello ksh: abc1=hello: not found $ echo $abc1 ksh: abc1: parameter not set It works when I specify the full variable name $ abc1=hello $ echo $abc1 hello ... (2 Replies)
Discussion started by: Chong Lee
2 Replies

2. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

3. Shell Programming and Scripting

cd command doesn't work through variables

Hi.... cd command is not working when dual string drive/volume name is passed to cd through variables....... For Ex.... y=/Volumes/Backup\ vipin/ cd $y the above command gives error....... anyone with a genuine solution ? (16 Replies)
Discussion started by: vipinchauhan222
16 Replies

4. Shell Programming and Scripting

SED 4.1.4 - INI File Change Problem in Variables= in Specific [Sections] (Guru Help)

GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32 I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)
Discussion started by: JakFrost
5 Replies

5. Shell Programming and Scripting

Sed with variables problem

I am writing a script with a sed call that needs to use a variable and still have quotations be present in the substitution. Example: sed -i "s/Replacable.\+$/Replaced="root@$VAR"/g" this outputs: where $VAR = place Replaced=root@place and i need Replaced="root@place" ... (2 Replies)
Discussion started by: mcdef
2 Replies

6. Shell Programming and Scripting

reading external variables does not work

... declare vINIFILE vINIFILE=$1 ... echo "The name of the File is $vINIFILE" >>mail_tmp echo "" >> mail_tmp.$$ ... grep RUNJOB=0 $vINIFILE >>tmp_filter ... So the strange is in echo-statement I get the correct output for $vINIFILE wrtitten into the file mail_tmp. But the... (2 Replies)
Discussion started by: ABE2202
2 Replies

7. Shell Programming and Scripting

Perl variables inside Net::Telnet::Cisco Module doesn't work

I am writing perl script to configure Cisco device but Variables inside Net::Telnet::Cisco Module doesn't work and passed to device without resolving. Please advise. here is a sample of script: use Net::Telnet::Cisco; $device = "10.14.199.1"; ($o1, $o2, $o3, $o4) = split(/\./,$device);... (5 Replies)
Discussion started by: ahmed_zaher
5 Replies

8. UNIX for Dummies Questions & Answers

Why does this SED example work?

$ x="/home/guru/temp/f1.txt" $ echo $x | sed 's^.*/^^' This will give the absolute path f1.txt. I don't understand WHY it works. How is it determining the last "/" character exactly? (7 Replies)
Discussion started by: glev2005
7 Replies

9. Shell Programming and Scripting

Problem with variables in sed

Hello! I have a problem to insert variables with sed... And I can't find the solution. :confused: I would like to display one/few line(s) between 2 values. This line works well sed -n '/Dec 12 10:42/,/Dec 12 10:47/p' Thoses lines with variables doesn't work and I don't find the... (2 Replies)
Discussion started by: Castelior
2 Replies

10. Shell Programming and Scripting

[Bash] passing variables to executable doesn't work

Bash version 4.4.20 / Ubuntu 16.0.4 Hello, I tried to write a script that gathers some data and passes them to an executable. The executed application answers with an error. The echo output in the script returns correct values. If I copy/paste the last echo command, it get's executed... (2 Replies)
Discussion started by: sushi2k7
2 Replies
Bio::Tools::Protparam(3pm)				User Contributed Perl Documentation				Bio::Tools::Protparam(3pm)

NAME
Bio::Tools::Protparam - submit to and parse output from protparam ; SYNOPSIS
my $gb = new Bio::DB::GenBank(-retrievaltype => 'tempfile' , -format => 'Fasta'); my @ids=qw(O14521 O43709 O43826); my $seqio = $gb->get_Stream_by_acc(@ids ); while( my $seq = $seqio->next_seq ) { my $pp = Protparam->new(seq=>$seq->seq); print "ID : ", $seq->display_id," ", "Amino acid number : ",$pp->amino_acid_number()," ", "Number of negative amino acids : ",$pp->num_neg()," ", "Number of positive amino acids : ",$pp->num_pos()," ", "Molecular weight : ",$pp->molecular_weight()," ", "Theoretical pI : ",$pp->theoretical_pI()," ", "Total number of atoms : ", $pp->total_atoms()," ", "Number of carbon atoms : ",$pp->num_carbon()," ", "Number of hydrogen atoms : ",$pp->num_hydrogen()," ", "Number of nitrogen atoms : ",$pp->num_nitro()," ", "Number of oxygen atoms : ",$pp->num_oxygen()," ", "Number of sulphur atoms : ",$pp->num_sulphur()," ", "Half life : ", $pp->half_life()," ", "Instability Index : ", $pp->instability_index()," ", "Stability class : ", $pp->stability()," ", "Aliphatic_index : ",$pp->aliphatic_index()," ", "Gravy : ", $pp->gravy()," ", "Composition of A : ", $pp->AA_comp('A')," ", "Composition of R : ", $pp->AA_comp('R')," ", "Composition of N : ", $pp->AA_comp('N')," ", "Composition of D : ", $pp->AA_comp('D')," ", "Composition of C : ", $pp->AA_comp('C')," ", "Composition of Q : ", $pp->AA_comp('Q')," ", "Composition of E : ", $pp->AA_comp('E')," ", "Composition of G : ", $pp->AA_comp('G')," ", "Composition of H : ", $pp->AA_comp('H')," ", "Composition of I : ", $pp->AA_comp('I')," ", "Composition of L : ", $pp->AA_comp('L')," ", "Composition of K : ", $pp->AA_comp('K')," ", "Composition of M : ", $pp->AA_comp('M')," ", "Composition of F : ", $pp->AA_comp('F')," ", "Composition of P : ", $pp->AA_comp('P')," ", "Composition of S : ", $pp->AA_comp('S')," ", "Composition of T : ", $pp->AA_comp('T')," ", "Composition of W : ", $pp->AA_comp('W')," ", "Composition of Y : ", $pp->AA_comp('Y')," ", "Composition of V : ", $pp->AA_comp('V')," ", "Composition of B : ", $pp->AA_comp('B')," ", "Composition of Z : ", $pp->AA_comp('Z')," ", "Composition of X : ", $pp->AA_comp('X')," "; } DESCRIPTION
This module takes an amino acid sequence and submits it to the Protparam program at www.expasy.org/cgi-bin/protparam. Many properties of the submitted sequence are returned. AUTHOR
Richard Dobson, r.j.dobson at qmul dot ac dot uk new Title : new Usage : $pp = Protparam->new(seq=>$seq->seq); Function : Creates a new Protparam object Returns : A Protparam object Args : A sequence num_neg Title : num_neg Usage : $pp->num_neg() Function : Retrieves the number of negative amino acids in a sequence Returns : Returns the number of negative amino acids in a sequence Args : none num_pos Title : num_pos Usage : $pp->num_pos() Function : Retrieves the number of positive amino acids in a sequence Returns : Returns the number of positive amino acids in a sequence Args : none amino_acid_number Title : amino_acid_number Usage : $pp->amino_acid_number() Function : Retrieves the number of amino acids within a sequence Returns : Returns the number of amino acids within a sequence Args : none total_atoms Title : total_atoms Usage : $pp->total_atoms() Function : Retrieves the total number of atoms within a sequence Returns : Returns the total number of atoms within a sequence Args : none molecular_weight Title : molecular_weight Usage : $pp->molecular_weight() Function : Retrieves the molecular weight of a sequence Returns : Returns the molecular weight of a sequence Args : none theoretical_pI Title : theoretical_pI Usage : $pp->theoretical_pI() Function : Retrieve the theoretical pI for a sequence Returns : Return the theoretical pI for a sequence Args : none num_carbon Title : num_carbon Usage : $pp->num_carbon() Function : Retrieves the number of carbon atoms in a sequence Returns : Returns the number of carbon atoms in a sequence Args : none num_hydrogen Title : num_hydrogen Usage : $pp->num_hydrogen Function : Retrieves the number of hydrogen atoms in a sequence Returns : Returns the number of hydrogen atoms in a sequence Args : none num_nitro Title : num_nitro Usage : $pp->num_nitro Function : Retrieves the number of nitrogen atoms in a sequence Returns : Returns the number of nitrogen atoms in a sequence Args : none num_oxygen Title : num_oxygen Usage : $pp->num_oxygen() Function : Retrieves the number of oxygen atoms in a sequence Returns : Returns the number of oxygen atoms in a sequence Args : none num_sulphur Title : num_sulphur Usage : $pp->num_sulphur() Function : Retrieves the number of sulphur atoms in a sequence Returns : Returns the number of sulphur atoms in a sequence Args : none half_life Title : half_life Usage : $pp->half_life() Function : Retrieves the half life of a sequence Returns : Returns the half life of a sequence Args : none instability_index Title : instability_index Usage : $pp->instability_index() Function : Retrieves the instability index of a sequence Returns : Returns the instability index of a sequence Args : none stability Title : stability Usage : $pp->stability() Function : Calculates whether the sequence is stable or unstable Returns : 'stable' or 'unstable' Args : none aliphatic_index Title : aliphatic_index Usage : $pp->aliphatic_index() Function : Retrieves the aliphatic index of the sequence Returns : Returns the aliphatic index of the sequence Args : none gravy Title : gravy Usage : $pp->gravy() Function : Retrieves the grand average of hydropathicity (GRAVY) of a sequence Returns : Returns the grand average of hydropathicity (GRAVY) of a sequence Args : none AA_comp Title : AA_comp Usage : $pp->AA_comp('P') Function : Retrieves the percentage composition of a given amino acid for a sequence Returns : Returns the percentage composition of a given amino acid for a sequence Args : A single letter amino acid code eg A, R, G, P etc perl v5.14.2 2012-03-02 Bio::Tools::Protparam(3pm)
All times are GMT -4. The time now is 05:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy