Sponsored Content
Top Forums Shell Programming and Scripting how I can add a constant to a field without changing the file format Post 302424959 by Scott on Wednesday 26th of May 2010 06:25:11 PM
Old 05-26-2010
Quote:
Originally Posted by curleb
I'm guessing at field defs here, but something like-a-dis:
Code:
$ awk '{printf "%-4s%7d  %-4s%-4s%-2s%3.d\n",$1,$2,$3,$4,$5,($6-34)}' Edit8
ATOM    918  N   GLY B  69
ATOM    919  CA  GLY B  69
ATOM    920  C   GLY B  69
ATOM    921  O   GLY B  69
ATOM    922  H   GLY B  69
ATOM    923  HA2 GLY B  69
ATOM    924  HA3 GLY B  69
ATOM    925  N   MET B  70
ATOM    926  CA  MET B  70
ATOM    927  C   MET B  70
ATOM    928  O   MET B  70
ATOM    929  CB  MET B  70
ATOM    930  CG  MET B  70
ATOM    931  SD  MET B  70
ATOM    932  CE  MET B  70
ATOM    933  H   MET B  70
ATOM    934  HA  MET B  70
ATOM    935  HB2 MET B  70
ATOM    936  HB3 MET B  70
ATOM    937  HG2 MET B  70
ATOM    938  HG3 MET B  70
ATOM    939  HE1 MET B  70
ATOM    940  HE2 MET B  70
ATOM    941  HE3 MET B  70

or, if you prefer concise and/or succinct...scottn posted something short and sweet. Only seems to shift $6 just a tad left...
Code:
$ awk '{X = $6 - 34; sub($6, X)}1' Edit8
ATOM    918  N   GLY B 69     -11.855   8.675 -11.404  1.00  0.00           N
ATOM    919  CA  GLY B 69     -13.297   8.831 -11.189  1.00  0.00           C
ATOM    920  C   GLY B 69     -13.977   7.468 -11.253  1.00  0.00           C
ATOM    921  O   GLY B 69     -14.817   7.213 -12.116  1.00  0.00           O
ATOM    922  H   GLY B 69     -11.342   7.827 -11.132  1.00  0.00           H
ATOM    923  HA2 GLY B 69     -13.483   9.303 -10.207  1.00  0.00           H
ATOM    924  HA3 GLY B 69     -13.734   9.500 -11.952  1.00  0.00           H
ATOM    925  N   MET B 70     -13.601   6.588 -10.332  1.00  0.00           N
ATOM    926  CA  MET B 70     -14.127   5.222 -10.341  1.00  0.00           C
ATOM    927  C   MET B 70     -15.232   5.094  -9.286  1.00  0.00           C
ATOM    928  O   MET B 70     -16.396   4.872  -9.620  1.00  0.00           O
ATOM    929  CB  MET B 70     -12.929   4.298 -10.093  1.00  0.00           C
ATOM    930  CG  MET B 70     -13.316   2.824 -10.092  1.00  0.00           C
ATOM    931  SD  MET B 70     -14.028   2.373 -11.684  1.00  0.00           S
ATOM    932  CE  MET B 70     -14.384   0.636 -11.368  1.00  0.00           C
ATOM    933  H   MET B 70     -12.859   6.880  -9.688  1.00  0.00           H
ATOM    934  HA  MET B 70     -14.557   4.991 -11.333  1.00  0.00           H
ATOM    935  HB2 MET B 70     -12.161   4.469 -10.870  1.00  0.00           H
ATOM    936  HB3 MET B 70     -12.447   4.551  -9.131  1.00  0.00           H
ATOM    937  HG2 MET B 70     -12.421   2.209  -9.894  1.00  0.00           H
ATOM    938  HG3 MET B 70     -14.041   2.627  -9.283  1.00  0.00           H
ATOM    939  HE1 MET B 70     -15.076   0.527 -10.513  1.00  0.00           H
ATOM    940  HE2 MET B 70     -14.852   0.168 -12.252  1.00  0.00           H
ATOM    941  HE3 MET B 70     -13.456   0.082 -11.135  1.00  0.00           H

Ah.. good point Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing particular field in fixed width file

I have a fixed width file and i need to change 36th field to "G" in for about random 20 records? How can I do it? (4 Replies)
Discussion started by: dsravan
4 Replies

2. UNIX for Dummies Questions & Answers

how to add a constant value to a column in a file using unix command

I have a file like this 1 chr1 3661579 3662579 2 chr1 4350395 4351395 3 chr1 4399322 4400322 4 chr1 4486494 4487494 5 chr1 4775807 4776807 6 chr1 4775807 4776807 7 chr1 4775807 4776807 8 chr1 4796973 4797973 9 chr1 4846774 4847774... (3 Replies)
Discussion started by: sunsnow86
3 Replies

3. Shell Programming and Scripting

Problem with changing field separators in a file

I have a file with content as shown below. cat t2 : 100,100,"X",1234,"12A",,,"ab,c" Comma is the field seperator, however string fields will be within double quotes and comma within double quotes should not be treated as field seperator. I am trying to replace this field seperator to a... (7 Replies)
Discussion started by: mk1216
7 Replies

4. Shell Programming and Scripting

Howto add a constant column to the text file

Hi, I am converting a .DBF file to pipe delimited file my requirement is like lets say my .DBF is residing in path /a/b/c/d/f/abc.DBF I need my .txt file as having a column with source _cd =f sample data in .DBF in folder "f" c1 c2 c3 1 2 3 in txt file it should be... (4 Replies)
Discussion started by: angel12345
4 Replies

5. Shell Programming and Scripting

[Solved] Need help changing a field from MM/DD/YY to DD/MM/YY format

Hi, I need help changing a field from MM/DD/YY to DD/MM/YY format. Suppose a file a.csv. The record is "11/16/09","ABC"," 1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD" "11/16/09","PQR"," 2","EU","520892427","1","600","31351000","5467897","ANR BANK CO.... (4 Replies)
Discussion started by: Gangadhar Reddy
4 Replies

6. Shell Programming and Scripting

Changing field X in file

/etc/newsyslog.conf on a Mac OSX system contains: # configuration file for newsyslog # $FreeBSD: /repoman/r/ncvs/src/etc/newsyslog.conf,v 1.50 2005/03/02 00:40:55 brooks Exp $ # # Entries which do not specify the '/pid_file' field will cause the # syslogd process to be signalled when that... (3 Replies)
Discussion started by: jnojr
3 Replies

7. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

8. Shell Programming and Scripting

Rows to columns with first field constant

Hi Friends, I have tried many options to convert rows to column in below fashion. Can you help me pls? input file: kamal|1,2,3|4,5,6|7,8,9 mich|4,7,4|6,7,9 jose|1,1,2|3,3,2|5,5,0 output required: kamal|1,2,3 kamal|4,5,6 kamal|7,8,9 mich|4,7,4 mich|6,7,9 jose|1,1,2 jose|3,3,2... (2 Replies)
Discussion started by: suresh3566
2 Replies

9. UNIX for Dummies Questions & Answers

Changing the file name format

Hello all, I am tryign to change the format of files (which are many in numbers). They at present are named like this: SomeProcess_M-130_100_1_3BR.root SomeProcess_M-130_101_2_3BX.root SomeProcess_M-130_103_3_3RY.root SomeProcess_M-130_105_1_3GH.root SomeProcess_M-130_99_1_3LF.root... (7 Replies)
Discussion started by: emily
7 Replies

10. UNIX for Advanced & Expert Users

Help changing date format in the nth field

Hi, I have two (2) things that I want to do. First is to change the date format that is in the nth field from MM/DD/YY to YY/MM/DD. Preferably, I wish I know how to make it a 4-digit year but I don't. Problem is I can only assume it is a 20 century Second is somehow know how to figure out... (1 Reply)
Discussion started by: newbie_01
1 Replies
Address(3pm)						User Contributed Perl Documentation					      Address(3pm)

NAME
Palm::Address - Handler for Palm AddressBook databases SYNOPSIS
use Palm::Address; DESCRIPTION
The Address PDB handler is a helper class for the Palm::PDB package. It parses AddressBook databases. AppInfo block The AppInfo block begins with standard category support. See Palm::StdAppInfo for details. Other fields include: $pdb->{appinfo}{lastUniqueID} $pdb->{appinfo}{dirtyFields} I don't know what these are. $pdb->{appinfo}{fieldLabels}{name} $pdb->{appinfo}{fieldLabels}{firstName} $pdb->{appinfo}{fieldLabels}{company} $pdb->{appinfo}{fieldLabels}{phone1} $pdb->{appinfo}{fieldLabels}{phone2} $pdb->{appinfo}{fieldLabels}{phone3} $pdb->{appinfo}{fieldLabels}{phone4} $pdb->{appinfo}{fieldLabels}{phone5} $pdb->{appinfo}{fieldLabels}{phone6} $pdb->{appinfo}{fieldLabels}{phone7} $pdb->{appinfo}{fieldLabels}{phone8} $pdb->{appinfo}{fieldLabels}{address} $pdb->{appinfo}{fieldLabels}{city} $pdb->{appinfo}{fieldLabels}{state} $pdb->{appinfo}{fieldLabels}{zipCode} $pdb->{appinfo}{fieldLabels}{country} $pdb->{appinfo}{fieldLabels}{title} $pdb->{appinfo}{fieldLabels}{custom1} $pdb->{appinfo}{fieldLabels}{custom2} $pdb->{appinfo}{fieldLabels}{custom3} $pdb->{appinfo}{fieldLabels}{custom4} $pdb->{appinfo}{fieldLabels}{note} These are the names of the various fields in the address record. $pdb->{appinfo}{country} An integer: the code for the country for which these labels were designed. The country name is available as $Palm::Address::countries[$pdb->{appinfo}{country}]; $pdb->{appinfo}{misc} An integer. The least-significant bit is a flag that indicates whether the database should be sorted by company. The other bits are reserved. Sort block $pdb->{sort} This is a scalar, the raw data of the sort block. Records $record = $pdb->{records}[N]; $record->{fields}{name} $record->{fields}{firstName} $record->{fields}{company} $record->{fields}{phone1} $record->{fields}{phone2} $record->{fields}{phone3} $record->{fields}{phone4} $record->{fields}{phone5} $record->{fields}{address} $record->{fields}{city} $record->{fields}{state} $record->{fields}{zipCode} $record->{fields}{country} $record->{fields}{title} $record->{fields}{custom1} $record->{fields}{custom2} $record->{fields}{custom3} $record->{fields}{custom4} $record->{fields}{note} These are scalars, the values of the various address book fields. $record->{phoneLabel}{phone1} $record->{phoneLabel}{phone2} $record->{phoneLabel}{phone3} $record->{phoneLabel}{phone4} $record->{phoneLabel}{phone5} Most fields in an AddressBook record are straightforward: the "name" field always gives the person's last name. The "phoneN" fields, on the other hand, can mean different things in different records. There are five such fields in each record, each of which can take on one of eight different values: "Work", "Home", "Fax", "Other", "E-mail", "Main", "Pager" and "Mobile". The $record->{phoneLabel}{phone*} fields are integers. Each one is an index into @Palm::Address::phoneLabels, and indicates which particular type of phone number each of the $record->{phone*} fields represents. $record->{phoneLabel}{display} Like the phone* fields above, this is an index into @Palm::Address::phoneLabels. It indicates which of the phone* fields to display in the list view. $record->{phoneLabel}{reserved} I don't know what this is. METHODS
new $pdb = new Palm::Address; Create a new PDB, initialized with the various Palm::Address fields and an empty record list. Use this method if you're creating an Address PDB from scratch. new_Record $record = $pdb->new_Record; Creates a new Address record, with blank values for all of the fields. The AppInfo block will contain only an "Unfiled" category, with ID 0. "new_Record" does not add the new record to $pdb. For that, you want "$pdb->append_Record". 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) BUGS
The new() method initializes the AppInfo block with English labels and "United States" as the country. perl v5.10.1 2010-02-23 Address(3pm)
All times are GMT -4. The time now is 09:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy