to delete a column in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers to delete a column in unix
# 1  
Old 11-20-2006
to delete a column in unix

Hai

Please let me know the command in unix(command mode ) from a file that deletes the whole column (not 1st and last column )& replace with numbers starting from 1.

Regards
suneetha.
# 2  
Old 11-20-2006
You need to post a snippet of the sample input file, as well as a sample of expected output. We also need to know how your fields are delimited.

Cheers
ZB
# 3  
Old 11-20-2006
regarding delete command in unix

Hai

This is the format from which i want to delete the 2nd column and i have to replace it with numbers starting from 1. this file contains 1000 lines of the below format.

ATOM 131 N ASN I 19 13.270 -37.510 4.242 1.00 57.52
ATOM 132 CA ASN I 19 11.912 -37.066 4.598 1.00 57.72

plz let me know the command in unix in command mode.

Regards
suneetha.
# 4  
Old 11-20-2006
Do not create multiple threads for the same topic. I have merged the threads.
# 5  
Old 12-12-2006
Bug

Lets assume that your input filename is infile.txt
Here is the code that might solve your problem Smilie

cat -n infile.txt | cut -f1 | tr -d " " > tempfile2
cut -d" " -f1 infile.txt > tempfile1
cut -d" " -f3- infile.txt > tempfile3

paste -d" " tempfile1 tempfile2 tempfile3 > outfile.txt


Since we are not actually reading each, this program will run really very fast Smilie .

Does this serve the purpose?
# 6  
Old 12-12-2006
Code:
awk ' { $2=NR; print }' file

# 7  
Old 12-12-2006
Hey m not trying 2 cross ne1....

m jus askin 4 knowledge....wont this hav performance issue as compared to cut?

Which one is betr...i had a similar thing done for 150k records, so wud prefer using the best!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to compare 3rd column value with first column and display

Hello Team, My source data (INput) is like below EPIC1 router EPIC2 Targetdefinition Exp1 Expres rtr1 Router SQL SrcQual Exp1 Expres rtr1 Router EPIC1 Targetdefinition My output like SQL SrcQual Exp1 Expres Exp1 Expres rtr1 Router rtr1 Router EPIC1 Targetdefinition... (5 Replies)
Discussion started by: sekhar.lsb
5 Replies

2. Shell Programming and Scripting

Delete part of a column

I want to delete a part of the 4th column from the given file below: <Text Text_ID="10155645315851111_10155645333076543" From="460350337461111" Created="2011-03-16T17:05:37+0000" use_count="123">This is the first text</Text> <Text Text_ID="10155645315851111_10155645317023456"... (2 Replies)
Discussion started by: my_Perl
2 Replies

3. Shell Programming and Scripting

Delete last characters in each column

I need to delete the last 11 characters from each number and they are all in the same line (each is in a different column): -6.89080901827020800000 3.49348891708562325136 1.47988367839905286876 -2.29707635413510400000 -3.49342364708562325136 -4.43758473239905286876 -2.29707635413510400000... (14 Replies)
Discussion started by: rogeriog.em
14 Replies

4. Shell Programming and Scripting

Delete a row if either of column value is zero

Hi, My input file is this way 1.1 0.0 2.4 3.5 7.9 1.8 22.3 4.7 8.9 0.9 1.3 0.0 3.4 5.6 0.0 1.1 2.2 0.0 0.0 1.1 0.0 0.0 3.4 5.6 I would like to delete the entire row, if either of 2nd and 3rd columns are 0.0. Please note that my values are all decimal values. So, my output would... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

5. UNIX for Advanced & Expert Users

Copy a column to another column in UNIX fixedwidth file

Hi All, I have a fixedwidth file of length 3000. Now i want to copy a column of 4 chars i.e( length 1678-1681) to column 1127 – 1171 to the same file. Please let me know how can i achive using a single command in fixed width file. Also source column length is 4 chars and target column length... (4 Replies)
Discussion started by: kiranparsha
4 Replies

6. Shell Programming and Scripting

delete the same column

var1 var2 var3 var4 var5 var6.... A G A T G T G A A A A A A A A A A A G A G T A T let's call this "file1.txt" we can see that var2 and var5 have the idential values. I would like to make a script so that if any variables (could be more than 2) have the identical values, i want to... (4 Replies)
Discussion started by: johnkim0806
4 Replies

7. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

8. Shell Programming and Scripting

delete first column

Dear All, I need to delete the first column, which blank in the tab delimited file and i need to print all the other columns with out disturbing the format of the file. I have tried with the followings and its not working for my case awk '{$1=""}1' file > newfilecut -d, -f2- dataCan anyone... (6 Replies)
Discussion started by: Fredrick
6 Replies

9. Shell Programming and Scripting

Delete first row last column

Hi All, I am having following file and I want to delete 1 row last column. Current File Content: ================ procedure test421 put_line procedure test321 test421 procedure test521 test321 procedure test621 test521 Expected File Content: =========================== procedure... (3 Replies)
Discussion started by: susau_79
3 Replies

10. UNIX for Dummies Questions & Answers

delete 7th column in unix

Hello., i have a file with 15 column. i want to remove the 7th column from the file. i am trying to use awk to delete the 7th column. can anyone help me how to do this thanks (6 Replies)
Discussion started by: pavan_test
6 Replies
Login or Register to Ask a Question