LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2014, 10:22 AM   #1
rama_david
LQ Newbie
 
Registered: Mar 2014
Posts: 1

Rep: Reputation: Disabled
Post The file editing through linux command


Hi friends
I am new to linux.
I have the .pdb file like the

....
ATOM 1 N MET 1 54.673 11.020 11.759 1.00 0.00
ATOM 2 HN1 MET 1 54.560 11.703 11.010 1.00 0.00
ATOM 3 HN2 MET 1 55.655 10.817 11.946 1.00 0.00
ATOM 4 HN3 MET 1 54.425 11.407 12.670 1.00 0.00
ATOM 5 CA MET 1 53.903 9.795 11.449 1.00 0.00
ATOM 6 C MET 1 54.068 8.797 12.543 1.00 0.00
.....
Now I want to add the column containing the word ¨ A ¨ ( throughout the file ) at 25th column and delete the column 27 ( throughout the file )..
how to do it with the linux command ??

I will be a very thankful to you for help
 
Old 03-17-2014, 10:58 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
what have you tried and where are you stuck. you may want to look into the cut, paste, awk, ... commands.
 
1 members found this post helpful.
Old 03-17-2014, 05:23 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,003

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
I'm sure the script guys could make a simple script starting with "for"

Can you use nano, vi or vim to edit with?

Others

http://www.thegeekstuff.com/2009/07/...-text-editors/
 
Old 03-17-2014, 08:30 PM   #4
padeen
Member
 
Registered: Sep 2009
Location: Perth, W.A.
Distribution: Slackware, Debian, Gentoo, FreeBSD, OpenBSD
Posts: 208

Rep: Reputation: 41
Cut 27th char is `cut --complement -c 27`, add A to column 25 is `sed -e 's/\(.\{25\}\)/\1A/'` . You can pipe them together (depending on which action takes place first):
Code:
sed -e 's/\(.\{25\}\)/\1A/' input_file_name | cut --complement -c 27 > output_file_name
"complement" is a GNU extension. Gets more tricky if you're not using GNU; probably have to use a small awk or sed script.

Last edited by padeen; 03-17-2014 at 08:37 PM.
 
1 members found this post helpful.
Old 03-20-2014, 01:01 AM   #5
Norseman01
Member
 
Registered: Nov 2012
Posts: 85

Rep: Reputation: Disabled
Maybe this will help.

Prompt:> cat orgdata
ATOM 1 N MET 1 54.673 11.020 11.759 1.00 0.00
ATOM 2 HN1 MET 1 54.560 11.703 11.010 1.00 0.00
ATOM 3 HN2 MET 1 55.655 10.817 11.946 1.00 0.00
ATOM 4 HN3 MET 1 54.425 11.407 12.670 1.00 0.00
ATOM 5 CA MET 1 53.903 9.795 11.449 1.00 0.00
ATOM 6 C MET 1 54.068 8.797 12.543 1.00 0.00

Prompt:> cat cmd
sed -e 's/\(.\{25\}\)/\1A/' orgdata | cut --complement -c 27 >moddata

Prompt:> cat moddata
ATOM 1 N MET 1 54.673 11.A20 11.759 1.00 0.00
ATOM 2 HN1 MET 1 54.560 1A.703 11.010 1.00 0.00
ATOM 3 HN2 MET 1 55.655 1A.817 11.946 1.00 0.00
ATOM 4 HN3 MET 1 54.425 1A.407 12.670 1.00 0.00
ATOM 5 CA MET 1 53.903 9.A95 11.449 1.00 0.00
ATOM 6 C MET 1 54.068 8.7A7 12.543 1.00 0.00

Prompt:>

I doubt the modified data lines are what you want.

Problem: This is a "Delimited" database file.

How do I know? Same number of groups on the line
with the same delimiter between each group.
Total line lengths differ.

awk is the choice here. do a man awk #and read
do an info awk #and read

This is going to sound harsh but it is true:
If you have never programmed a computer, take a beginner class.
Learn (remember if you had the class) things like:
for/next, if/else/endif and such - aka program controlls
read/write commands, assign commands, what a var (variable) is.

Anyone can use Linux for ordinary Office use. google OpenOffice,
but to get the most from it you need programming skills.

Am I trying to scare you? NO!!
Pick a determined attitude, go in with your eyes open and in no
time at all you will be teaching us.

The use of awk is to create one var for each "field" in the line.
Then each var can be manipulated individually, realigned, stored or
printed or whatever.
Each field can be assigned to a var (database calls them field names),
something like: f001=ATOM
f002=1
f003=N ... and so on
next line: f001=ATOM
f002=2
f003=HN1
... and so on

ATOM 1 N MET 1 54.673 11.020 11.759 1.00 0.00
ATOM 2 HN1 MET 1 54.560 11.703 11.010 1.00 0.00

if we revert to the old IBM Punch Card aka Standard Data Format
we will see the problem:
123456789x123456789x1234X6X789x123456789x123456789x
ATOM 1 N MET 1 54.673 11.020 11.759 1.00 0.00
ATOM 2 HN1 MET 1 54.560 11.703 11.010 1.00 0.00
see the "X"?
Col-25 and Col-27 is in different places on different lines.


it should be:
123456789x123456789x1234X6X89x123456789x123456789x
ATOM1N MET154.67311.02011.7591.000.00 These two lines should be
ATOM2HN1MET154.56011.70311.0101.000.00 the same length, see f003
ie... f001,4
f002,1,0
f003,3
f004,3
f005,1,0
f006,6,3
... and so on
Last line of fields just above read as:
name,width in columns,# decimal places
f006 6 3 #max number 99.999

Spaces or (more commonly) commas are added at print/display time.
ANY byte can be used as a delimiter as long as it is NOT in any
field containing data. If one wishes to waste great amounts of
disk space one can place the delimiter in the database.
I count 10 fields and 9 delimiters in each line.
A database of 1 million lines which has 9 blanks in each line
wastes 9 million bytes of storage. Thus, fully delimited
storage of orgdata is a bad idea. It's also why, when posted,
this posting reads funny. The leading blanks are removed to save space.
The SDF method gets more
data stored in same space. (Assuming all or most fields are
not empty.)

So what are you looking to do?
A) Open and read line by line untill all read
B) break each line's fields into individual vars
C) determine which var(s) to modify/delete/whatever
D) do the modifictions
E) copy/print/store the re-assembled string
F) go to step A untill source is consumed
G) Oh-See-Seven (GONG) done

TIP:
Visual inspection of supplied data suggests:
Col25 = 25 - (MaxLineLength - CurrentLineLength)

Because the translation may not be saying what you are,
At this point I need to ask you:
Given:
ATOM 2 HN1 MET 1 54.560 11.703 11.010 1.00 0.00
Is this the desired result?
ATOM 2 HN1 MET 1 54.560 A 11703 11.010 1.00 0.00


Norseman01

Last edited by Norseman01; 03-20-2014 at 01:13 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shr command line file editing program? mrapathy Linux - Mobile 0 02-27-2014 10:45 PM
Command line text file viewing and editing - .odt etc. mitchellray Linux - Newbie 1 04-14-2009 03:41 PM
Editing an .iso file in linux linuxpokernut Linux - Newbie 8 09-26-2007 08:44 AM
editing a file in command line during ssh session...need advise! reddog1 SUSE / openSUSE 8 05-31-2006 09:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration