Sponsored Content
Top Forums Shell Programming and Scripting awk and gsub - how to replace only the first X occurrences Post 302456526 by quirkasaurus on Friday 24th of September 2010 12:01:10 PM
Old 09-24-2010
oops. sorry. didn't notice that.

Code:
cat text.txt |
awk '{
  if ( count < 2 ){
    gsub("CAR","REPLACE")
    count++
    }
  print
  }'

Code:
output:
REPLACE sweet head
hat red yellow
CAR book brown
tiger CAR cow CAR
CAR milk

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with AWK and gsub

Hello, I have a variable that displays the following results from a JVM.... 1602100K->1578435K I would like to collect the value of 1578435 which is the value after a garbage collection. I've tried the following command but it looks like I can't get the > to work. Any suggestions as... (4 Replies)
Discussion started by: npolite
4 Replies

2. Shell Programming and Scripting

awk gsub

Hi all I want to do a simple substitution in awk but I am getting unexpected output. My function accepts a time and then prints out a validation message if the time is valid. However some times may include a : and i want to strip this out if it exists before i get to the validation. I have shown... (4 Replies)
Discussion started by: pxy2d1
4 Replies

3. Shell Programming and Scripting

sed replace multiple occurrences on the same line, but not all

Hi there! I am really enjoying working with sed. I am trying to come up with a sed command to replace some occurrences (not all) in the same line, for instance: I have a command which the output will be: 200.300.400.5 0A 0B 0C 01 02 03 being that the last 6 strings are actually one... (7 Replies)
Discussion started by: ppucci
7 Replies

4. UNIX for Dummies Questions & Answers

Replace all occurrences of strings with parentheses

Hi, I tried to adapt bartus's solution to my problem, without success. I want to replace all the occurences of this: with: , where something can contain an arbitrary number of balanced parens and brakets. Any ideas ? Best, (1 Reply)
Discussion started by: ff1969ff1969
1 Replies

5. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

6. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

7. Shell Programming and Scripting

Search & replace content using awk/gsub

Hi, I have two files master.txt & reference.txt. Sample below Master.txt 2372,MTS,AP 919848001104,Airtel,DL 0819,MTS,MUM 919849788001,Airtel,AP 1430,Aircel MP,20 Reference.txt 2372,919848701430,46467 919848002372,2372,47195 2372,919849788001,59027 0819,028803,1 0819,029801,1... (2 Replies)
Discussion started by: siramitsharma
2 Replies

8. Shell Programming and Scripting

Search & Replace content of files using gsub in awk

Hi,I have 2 files master.txt & reference.txt as shown below & i require o/p as mentioned in file 3 using awk but content is not replacing properlymaster.txt:... (15 Replies)
Discussion started by: siramitsharma
15 Replies

9. Shell Programming and Scripting

Replace characters in string with awk gsub

Hi I have a source file that looks like a,b,c,d,e,f,g,h,t,DISTI(USD),MSRP(USD),DIST(EUR),MSRP(EUR),EMEA-DISTI(USD),EMEA-MSRP(USD),GLOBAl-DISTI(USD),GLOBAL-MSRP(USD),DISTI(GBP), MSRP(GBP) I want to basically change MSRP(USD) to MSRP,USD and DIST(EUR) to DIST,EUR and likewise for all i'm using... (3 Replies)
Discussion started by: r_t_1601
3 Replies

10. Shell Programming and Scripting

awk gsub command to replace multiple spaces

Hi Forum. I'm trying to cleanup the following data elements (To remove any occurences of commas and any extra spaces) while preserving the <TAB> delimiter using awk gsub but I have not been successful. Original Data: 4365 monte des source rue,, ,<TAB>trevost<TAB>QC Desired Data:... (1 Reply)
Discussion started by: pchang
1 Replies
babel(1)						      User's Reference Manual							  babel(1)

NAME
babel, obabel -- a converter for chemistry and molecular modeling data files SYNOPSIS
babel, [-H help-options] babel, [OPTIONS] [-i input-type] infile [-o output-type] outfile obabel [-H help-options] obabel [OPTIONS] [-i input-type | -: "SMILES-string"] infile [-o output-type] -O outfile DESCRIPTION
babel, is a cross-platform program designed to interconvert between many file formats used in molecular modeling and computational chemistry and related areas. obabel and babel, are slightly different. The first is closer to the normal Unix convention for commandline programs and more flexible when the user needs to specify parameter values on options. With babel this only works when the option is the last on the line; with obabel no such restriction applies. It further has a shortcut for entering SMILES strings, which can be used in place of an input file. Open Babel is also a complete programmers toolkit for developing chemistry software. For more information, se the Open Babel web pages <http://openbabel.org/>. OPTIONS
If only input and ouput files are given, Open Babel will guess the file type from the filename extension. -: "SMILES-string" Enter SMILES string and use it in place of an input file. The SMILES string should be enclosed in quotation marks. More than one can be used, and a molecule title can be included if enclosed in quotes. -a options Format-specific input options. See -H format-ID for options allowed by a particular format --addtotitle Append text to the current molecule title --addformula Append the molecular formula after the current molecule title -b Convert dative bonds: e.g., [N+]([O-])=O to N(=O)=O -c Center atomic coordinates at (0,0,0) -C Combine molecules in first file with others having the same name -e Continue after errors -d Delete Hydrogens ---errorlevel 2 Filter the level of errors and warnings displayed: 1 = critical errors only 2 = include warnings too (default) 3 = include informational messages too 4 = include "audit log" messages of changes to data 5 = include debugging messages too -f # For multiple entry input, start import with molecule # as the first entry -F Output the available fingerprint types -h Add hydrogens -H Output usage information -H format-ID Output formatting information and options for format specified -Hall Output formatting information and options for all formats -i<format-ID> Specifies input format, see below for the available formats -j --join Join all input molecules into a single output molecule entry -k Translate computational chemistry modeling keywords (e.g., GAMESS and Gaussian) -m Produce multiple output files, to allow: - Splitting one input file - put each molecule into consecutively numbered output files - Batch conversion - convert each of multiple input files into a specified output format -l # For multiple entry input, stop import with molecule # as the last entry -o format-ID Specifies output format, see below for the available formats -O outfile Specify the output file. This option applies to obabel only. -p Add Hydrogens appropriate for pH (use transforms in phmodel.txt) --property Add or replace a property (e.g., in an MDL SD file) -s SMARTS Convert only molecules matching the SMARTS pattern specified --separate Separate disconnected fragments into individual molecular records -t All input files describe a single molecule --title title Add or replace molecular title -x options Format-specific output options. See -H format-ID for options allowed by a particular format -v SMARTS Convert only molecules NOT matching SMARTS pattern specified -V Output version number and exit -z Compress the output with gzip FILE FORMATS
The following formats are currently supported by Open Babel: acr -- Carine ASCI Crystal alc -- Alchemy format arc -- Accelrys/MSI Biosym/Insight II CAR format [Read-only] bgf -- MSI BGF format box -- Dock 3.5 Box format bs -- Ball and Stick format c3d1 -- Chem3D Cartesian 1 format c3d2 -- Chem3D Cartesian 2 format caccrt -- Cacao Cartesian format cache -- CAChe MolStruct format [Write-only] cacint -- Cacao Internal format [Write-only] can -- Canonical SMILES format car -- Accelrys/MSI Biosym/Insight II CAR format [Read-only] ccc -- CCC format [Read-only] cdx -- ChemDraw binary format [Read-only] cdxml -- ChemDraw CDXML format cht -- Chemtool format [Write-only] cif -- Crystallographic Information File cml -- Chemical Markup Language cmlr -- CML Reaction format com -- Gaussian 98/03 Cartesian Input [Write-only] copy -- Copies raw text [Write-only] crk2d -- Chemical Resource Kit 2D diagram format crk3d -- Chemical Resource Kit 3D format csr -- Accelrys/MSI Quanta CSR format [Write-only] cssr -- CSD CSSR format [Write-only] ct -- ChemDraw Connection Table format dmol -- DMol3 coordinates format ent -- Protein Data Bank format fa -- FASTA format [Write-only] fasta -- FASTA format [Write-only] fch -- Gaussian formatted checkpoint file format [Read-only] fchk -- Gaussian formatted checkpoint file format [Read-only] fck -- Gaussian formatted checkpoint file format [Read-only] feat -- Feature format fh -- Fenske-Hall Z-Matrix format [Write-only] fix -- SMILES FIX format [Write-only] fpt -- Fingerprint format [Write-only] fract -- Free Form Fractional format fs -- Open Babel FastSearching database fsa -- FASTA format [Write-only] g03 -- Gaussian 98/03 Output [Read-only] g98 -- Gaussian 98/03 Output [Read-only] gam -- GAMESS Output [Read-only] gamin -- GAMESS Input [Write-only] gamout -- GAMESS Output [Read-only] gau -- Gaussian 98/03 Cartesian Input [Write-only] gjc -- Gaussian 98/03 Cartesian Input [Write-only] gjf -- Gaussian 98/03 Cartesian Input [Write-only] gpr -- Ghemical format gr96 -- GROMOS96 format [Write-only] hin -- HyperChem HIN format inchi -- IUPAC InChI [Write-only] inp -- GAMESS Input [Write-only] ins -- ShelX format [Read-only] jin -- Jaguar input format [Write-only] jout -- Jaguar output format [Read-only] mdl -- MDL MOL format mmd -- MacroModel format mmod -- MacroModel format mol -- MDL MOL format mol2 -- Sybyl Mol2 format molreport -- Open Babel molecule report [Write-only] moo -- MOPAC Output format [Read-only] mop -- MOPAC Cartesian format mopcrt -- MOPAC Cartesian format mopin -- MOPAC Internal mopout -- MOPAC Output format [Read-only] mpc -- MOPAC Cartesian format mpd -- Sybyl descriptor format [Write-only] mpqc -- MPQC output format [Read-only] mpqcin -- MPQC simplified input format [Write-only] nw -- NWChem input format [Write-only] nwo -- NWChem output format [Read-only] pc -- PubChem format [Read-only] pcm -- PCModel format pdb -- Protein Data Bank format pov -- POV-Ray input format [Write-only] pqs -- Parallel Quantum Solutions format prep -- Amber Prep format [Read-only] qcin -- Q-Chem input format [Write-only] qcout -- Q-Chem output format [Read-only] report -- Open Babel report format [Write-only] res -- ShelX format [Read-only] rxn -- MDL RXN format sd -- MDL MOL format sdf -- MDL MOL format smi -- SMILES format sy2 -- Sybyl Mol2 format tdd -- Thermo format test -- Test format [Write-only] therm -- Thermo format tmol -- TurboMole Coordinate format txyz -- Tinker MM2 format [Write-only] unixyz -- UniChem XYZ format vmol -- ViewMol format xed -- XED format [Write-only] xml -- General XML format [Read-only] xyz -- XYZ cartesian coordinates format yob -- YASARA.org YOB format zin -- ZINDO input format [Write-only] FORMAT OPTIONS
Individual file formats may have additional formatting options. Input format options are preceded by 'a', e.g. -as Output format options are preceded by 'x', e.g. -xn For further specific information and options, use -H<format-type> e.g., -Hcml EXAMPLES
Standard conversion: babel -ixyz ethanol.xyz -opdb ethanol.pdb Conversion from a SMI file in STDIN to a Mol2 file written to STDOUT: babel -ismi -omol2 Split a multi-molecule file into new1.smi, new2.smi, etc.: babel infile.mol new.smi -m SEE ALSO
obenergy(1), obfit(1), obgrep(1), obminimize(1), obprop(1), obrotate(1), obrotamer(1). The web pages for Open Babel can be found at: <http://openbabel.org/> AUTHORS
A cast of many, including the currrent maintainers Geoff Hutchison, Chris Morley, Michael Banck, and innumerable others who have contributed fixes and additions. For more contributors to Open Babel, see <http://openbabel.org/wiki/THANKS> COPYRIGHT
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. Some portions Copyright (C) 2001-2007 by Geoffrey R. Hutchison This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL- ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Open Babel 2.2 July 4, 2008 Open Babel 2.2
All times are GMT -4. The time now is 03:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy