column renumbering


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting column renumbering
# 1  
Old 03-16-2009
column renumbering

Hi,
I am a beginner in awk scripting! I need your help; I want to replace the fifth column number (which is 15 here) here in this file for example :

ATOM 142 N PRO A 15
ATOM 143 CD PRO A 15
ATOM 144 HD1 PRO A 15
ATOM 145 HD2 PRO A 15
ATOM 146 CA PRO A 15
ATOM 147 HA PRO A 15
ATOM 148 CB PRO A 15
ATOM 149 HB1 PRO A 15

with sequential numbering :

ATOM 142 N PRO A 1
ATOM 143 CD PRO A 2
ATOM 144 HD1 PRO A 3
ATOM 145 HD2 PRO A 4
ATOM 146 CA PRO A 5
ATOM 147 HA PRO A 6
ATOM 148 CB PRO A 7
ATOM 149 HB1 PRO A 8
with an awk shell script... I guess this is too simple a question!! but I would appreciate any suggestions from you...Smilie
thanks already.
# 2  
Old 03-16-2009
Quote:
Originally Posted by adak
Hi,
I am a beginner in awk scripting! I need your help; I want to replace the fifth column number (which is 15 here) here in this file for example :

ATOM 142 N PRO A 15
ATOM 143 CD PRO A 15
ATOM 144 HD1 PRO A 15
ATOM 145 HD2 PRO A 15
ATOM 146 CA PRO A 15
ATOM 147 HA PRO A 15
ATOM 148 CB PRO A 15
ATOM 149 HB1 PRO A 15

with sequential numbering :

ATOM 142 N PRO A 1
ATOM 143 CD PRO A 2
ATOM 144 HD1 PRO A 3
ATOM 145 HD2 PRO A 4
ATOM 146 CA PRO A 5
ATOM 147 HA PRO A 6
ATOM 148 CB PRO A 7
ATOM 149 HB1 PRO A 8
with an awk shell script... I guess this is too simple a question!! but I would appreciate any suggestions from you...Smilie
thanks already.
Code:
 awk '{$NF=NR}{print}' file

Regards
# 3  
Old 03-16-2009
Thanks a lot for your quick reply, but what if I want to replace this sequential numbers with an existing column? because this is not the last column of my file, this is the 6th column which I want to renumber sequentially...
if you could help me again, I will be more than thankful...
# 4  
Old 03-16-2009
Can you show a sample of the input and output.
# 5  
Old 03-16-2009
Replace $NF by your column number :
Code:
awk '{$2=NR}{print}' infile
ATOM 1 N PRO A 15
ATOM 2 CD PRO A 15
ATOM 3 HD1 PRO A 15
ATOM 4 HD2 PRO A 15
ATOM 5 CA PRO A 15
ATOM 6 HA PRO A 15
ATOM 7 CB PRO A 15
ATOM 8 HB1 PRO A 15

# 6  
Old 03-16-2009
Thanks a lot to all!
Goldoraak; it worked properly... :-)
adak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count Repetitive Number in a column and renumbering using awk

Unable to get the desired output. Need only the rows which has repeated values in column 5. Input File <tab separated file> chr1 3773797 3773797 CEP10 1 chr1 3773797 3773797 CEP104 2 chr1 3689350 3689350 SMIM1 2 chr1 3773797 3773797 CEP4 3 chr1 3773797 3773797 EP104 ... (7 Replies)
Discussion started by: himanshu
7 Replies

2. Shell Programming and Scripting

Renumbering files bash script

I am new to the world of Linux scripting, and would like to make the following 2 scripts: I have 67 files named Alk-0001.txt to Alk-0067.txt I would like them to be numbered Alk-002.txt to Alk-0134.txt eg Alk-0001.txt > Alk-0002.txt Alk-0002.txt > Alk-0004.txt Alk-0003.txt > Alk-0006.txt ... (3 Replies)
Discussion started by: tollyboy_uk
3 Replies

3. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

4. Shell Programming and Scripting

Renumbering of COBOL Source code

Hi, I have written awk script to replicate RENUM function of ISPF. Please anyone has simple script than that. awk '{i=i+10;line=substr($0,7,73); printf("%06d%s\n", i, line) }' ABC.cob where ABC.cob is Cobol source code. (4 Replies)
Discussion started by: kailas.girase
4 Replies

5. Shell Programming and Scripting

renumbering within a file

Hi All, I have 100 files named - rep-0.txt, rep-2.txt...rep-99.txt. They each contain information in the following format: abc 1 qwe asd 2 zxc poi 3 lkj pdh 4 ldf hgf 5 tyu i would like to re-number , so that all the new files (rep0.dat, rep1,dat....) have... (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

6. UNIX for Dummies Questions & Answers

renaming (renumbering) fasta files

I have a fasta file that looks like this: >Noname ACCAAAATAATTCATGATATACTCAGATCCATCTGAGGGTTTCACCACTTGTAGAGCTAT CAGAAGAATGTCAATCAACTGTCCGAGAAAAAAGAATCCCAGG >Noname ACTATAAACCCTATTTCTCTTTCTAAAAATTGAAATATTAAAGAAACTAGCACTAGCCTG ACCTTTAGCCAGACTTCTCACTCTTAATGCTGCGGACAAACAGA ... I want to... (2 Replies)
Discussion started by: Oyster
2 Replies

7. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

8. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

9. Shell Programming and Scripting

Renumbering files scripting help!

I am new to the world of UNIX scripting - and would like to make the following script: I have 100 files numbered 1-100. However - i would like to continue the file list - so that I add another 100 files following on, so that file 101 = 99; file 102 = 98 ; 103 = 97 and so on.... (basically ...... (6 Replies)
Discussion started by: AJC1985
6 Replies

10. UNIX for Dummies Questions & Answers

renumbering user id

Other than deleting and recreating a user can a users id number be changed? I need to have my user id the same on more than one system. (1 Reply)
Discussion started by: thumper
1 Replies
Login or Register to Ask a Question