Register
It is currently Sat Dec 20, 2014 2:53 am

Help making very simple Bash script!!


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Jun 01, 2009 4:08 pm   

Joined: Mon Jun 01, 2009 3:57 pm
Posts: 1
Hello,

I'm trying to modify a file which has weird column delimiters (a variable number of spaces, depending on the columns).

The file looks like this:

ATOM 148 N GLY B 1 2.150 -1.246 -0.905 1.00 0.00 N
ATOM 149 CA GLY B 1 2.840 -0.380 -1.790 1.00 0.00 C
ATOM 150 C GLY B 1 4.050 -1.070 -2.403 1.00 0.00 C
ATOM 151 O GLY B 1 4.390 -2.201 -2.053 1.00 0.00 O
etc


I need to modify column 2, such that the current value 'n' is replaced by 'n-147', in other words, I want:

ATOM 1 N GLY B 1 2.150 -1.246 -0.905 1.00 0.00 N
ATOM 2 CA GLY B 1 2.840 -0.380 -1.790 1.00 0.00 C
ATOM 3 C GLY B 1 4.050 -1.070 -2.403 1.00 0.00 C
ATOM 4 O GLY B 1 4.390 -2.201 -2.053 1.00 0.00 O

So simple and yet I can't get awk to do it properly without messing everything up. Can anyone help please? :(

Many thanks!!

T


Top
 Profile  
 PostPosted: Sun Jun 14, 2009 9:41 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
As long as your example is an accurate representation of the whole file, this should work:
Code:
awk '{$2 = ($2 -147); print $0}' file_name


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP