How to delete last 3 columns in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to delete last 3 columns in a file
# 1  
Old 07-10-2009
Data How to delete last 3 columns in a file

Hii I have a file which contains huge amounts of data.I just want to delete last 3 columns in the without changing its format.The file contains data as shown below
PDE 2001 10 29 202148.60 38.92 24.20 33 4.8 MLATH .F. .......
PDE 2001 10 29 203423.57 38.88 24.41 33 3.7 MLATH ... .......
PDE 2001 10 30 022401.80 35.92 23.90 5 3.5 MDATH ... .......
PDE 2001 10 30 061008.62 34.62 24.12 33 4.0 MLATH ... .......
PDE 2001 10 30 075220.80 38.12 23.21 7 3.0 MLATH ... .......
PDE 2001 10 30 101545.66 36.60 70.96 200 ... .......
PDE 2001 10 30 111050.30 37.10 21.57 5 3.0 MDATH ... .......

I want to delete the last 3 colums & the new file should look like
PDE 2001 10 29 202148.60 38.92 24.20 33 4.8
PDE 2001 10 29 203423.57 38.88 24.41 33 3.7
PDE 2001 10 30 022401.80 35.92 23.90 5 3.5
PDE 2001 10 30 061008.62 34.62 24.12 33 4.0
PDE 2001 10 30 075220.80 38.12 23.21 7 3.0
PDE 2001 10 30 101545.66 36.60 70.96 200
PDE 2001 10 30 111050.30 37.10 21.57 5 3.0

I tried using sed 's./.$//' filename
No change was thier
I tried even using cat rr.dat | cut -f1,2,3,4,5,6,7,8,9
no change was thier please tell me a solution for my problem

thanks
# 2  
Old 07-10-2009
Code:
 
cut -d " " -f1-9 file

# 3  
Old 07-10-2009
I used that cut command but i am getting an error
as shown below for the previous data
PDE 2001 10 29 202148.60 38.92 24.20 33 4.8
PDE 2001 10 29 203423.57 38.88 24.41 33 3.7
PDE 2001 10 30 022401.80 35.92 23.90 5
PDE 2001 10 30 061008.62 34.62 24.12 33 4.0
PDE 2001 10 30 075220.80 38.12 23.21 7
PDE 2001 10 30 101545.66 36.60 70.96 200
PDE 2001 10 30 111050.30 37.10 21.57 5
the last column contains some missing real values for example the 3rd ,5th & so on has the last column missing
i dont know why

thanks
# 4  
Old 07-10-2009
I don't see any values missing. I am getting the below output.


Code:
 
$ cut -d " " -f1-9 file1
PDE 2001 10 29 202148.60 38.92 24.20 33 4.8
PDE 2001 10 29 203423.57 38.88 24.41 33 3.7
PDE 2001 10 30 022401.80 35.92 23.90 5 3.5
PDE 2001 10 30 061008.62 34.62 24.12 33 4.0
PDE 2001 10 30 075220.80 38.12 23.21 7 3.0
PDE 2001 10 30 101545.66 36.60 70.96 200 ...
PDE 2001 10 30 111050.30 37.10 21.57 5 3.0

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete columns with a specific title XXX, where the position change in each file

Goodmorning, I know how to cut a string and a column, and how to find a word. I have a file with over 100 columns. All columns have a title in the first line. I have to delete all columns with the XXX title. I can't use cut -f because the position of XXX columns change in each file, and in... (14 Replies)
Discussion started by: echo manolis
14 Replies

2. Shell Programming and Scripting

Delete and insert columns in a tab delimited file

Hi all , I have a file having 12 columns tab delimited . I need to read this file and remove the column 3 and column 4 and insert a word in column 3 as "AVIALABLE " Is there a way to do this . I am trying like below Thanks DJ cat $FILENAME|awk -F"\t" '{ print $1 "\t... (3 Replies)
Discussion started by: Hypesslearner
3 Replies

3. Shell Programming and Scripting

How to delete a columns of a CSV file which has cell values with a string enclosed in " , "?

Hi How can I delete a columns from a CSV file which has comma separated value with a string enclosed in double quotes or square bracket and a comma in between? I have a csv file with below format. Template,Target Server,Target Component,Rule Group,Rule,Rule Reference Number,Rule... (7 Replies)
Discussion started by: Litu19
7 Replies

4. Shell Programming and Scripting

How to delete a column/columns of a CSV file which has cell values with a string enclosed in " , "?

How can I delete a column from a CSV file which has comma separated value with a string enclosed in double quotes and a comma in between? I have a file 44.csv with 4 lines including the header like the below format: column1, column2, column3, column 4, column5, column6 12,455,"string with... (6 Replies)
Discussion started by: dhruuv369
6 Replies

5. UNIX for Dummies Questions & Answers

Sed: delete columns 7,15,16

An extension from an earlier question. Now need a sed script to delete columns 7,15 and 16 from an example txt below.. Again, thanks in advance. 98M-01.WAV,98M,01,00:00:49,01:07:36:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"", 98L-01.WAV,98L,01,00:00:51,01:01:45:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"", (7 Replies)
Discussion started by: Vrc2250
7 Replies

6. Shell Programming and Scripting

Delete columns if a pattern met

Hi, I'd like to ask for some help with the following task, please: there is a big file with a header (this is file.in): NAME A_1.X A_1.Y A_1.Z B_1.X B_1.Y B_1.Z name1 AB 0.11 0.12 BB 0.45 0.67 name2 BB 0.34 0.56 AA 0.89 0.68 what I need is to recognize a pattern in the header of this... (10 Replies)
Discussion started by: zajtat
10 Replies

7. UNIX for Dummies Questions & Answers

How to delete columns with numbers in an excel file?

Dear all, I have one file (see below) with more then 100 columns and 2500 rows, and need only column which has GType in label with Alphabets, please help me to remove these columns with numbers. input file is n.201.GType n-201.Theta n-201.R n_1.GType n_1.Theta n_1.R... (6 Replies)
Discussion started by: AAWT
6 Replies

8. UNIX for Dummies Questions & Answers

Delete large number of columns rom file

Hi, I have a data file that contains 61 columns. I want to delete all the columns except columns, 3,6 and 8. The columns are tab de-limited. How would I achieve this on the terminal? Thanks (2 Replies)
Discussion started by: lost.identity
2 Replies

9. UNIX for Dummies Questions & Answers

delete lines and columns from a file

how do I delete the first 3 lines and the first column and the tab? infile: Colorspace 0 SA-Sample 1 in 32 FTab-Chars 10 Sequence-1 SINE1_7SL 282 Sequence-2 sapieTTns 289 Sequence-3 7SL_Hopns 289outfile: SINE1_7SL 282 sapieTTns 289 7SL_Hopns 289Thanks (4 Replies)
Discussion started by: jdhahbi
4 Replies

10. UNIX for Dummies Questions & Answers

delete some columns

I've got a data file like the following format. 196004010000 196004020000 8192 24 ueaag 98.793 18.750 20 ---- - 36 23 9999 314.161773681641 196004020000 196004030000 8192 24 ueaag 98.793 18.750 20 ---- - 36 23 9999 314.71533203125 196004030000 196004040000 8192 24... (7 Replies)
Discussion started by: su_in99
7 Replies
Login or Register to Ask a Question