delete lines and columns from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers delete lines and columns from a file
# 1  
Old 08-26-2010
delete lines and columns from a file

how do I delete the first 3 lines and the first column and the tab?

infile:
Code:
Colorspace    0
SA-Sample    1 in 32
FTab-Chars    10
Sequence-1    SINE1_7SL    282
Sequence-2    sapieTTns    289
Sequence-3    7SL_Hopns    289

outfile:
Code:
SINE1_7SL    282
sapieTTns    289
7SL_Hopns    289

Thanks
# 2  
Old 08-26-2010
Code:
awk 'NR>3{print $2"    "$3}' file

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 08-26-2010
Code:
# sed '1,3d;s/[^ ]* *//' infile
SINE1_7SL    282
sapieTTns    289
7SL_Hopns    289

# 4  
Old 08-26-2010
Updated.

Code:
awk 'NR>3{print $2 "\t" $3}' infile


Last edited by rdcwayx; 08-27-2010 at 12:02 AM..
# 5  
Old 08-26-2010
Quote:
Originally Posted by rdcwayx
Code:
awk 'NR>3{print $1 "\t" $3}' infile

You might want to specifically note the use of '\t\ rather than typing the tab character into the code. Easier to read for anybody who is coming along to maintain your script (assuming you are writing a script) and thus a good habit to get into. In the sed example above it's impossible to tell if that's a tab or space in the pattern. We assume tab given the requirements, but just to look at the command '\t' would be more informative.

Small typo in the code though:
Code:
awk 'NR>3{print $2 "\t" $3}' infile

 
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

Delete 40 lines after every 24 lines from a file

Hello, I have file of more than 10000 lines. I want to delete 40 lines after every 20 lines. e.g from a huge file, i want to delete line no from 34 - 74, then 94 - 134 etc and so on. Please let me know how i can do it. Best regards, (11 Replies)
Discussion started by: nehashine
11 Replies

4. 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

5. 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

6. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

7. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

8. UNIX for Dummies Questions & Answers

Adding lines and columns to a file

Hi everybody, I've got two simples file1 like: aaa aaa aaa bbb bbb bbb ccc ccc ccc and file2 like: 111 111 111 222 222 222 333 333 333 I need to: 1) add a line say "new line" as the first line of the file 2)add a column from file2 (say column3) to file1; the new column should... (14 Replies)
Discussion started by: zajtat
14 Replies

9. Shell Programming and Scripting

How to delete lines in a file that have duplicates or derive the lines that aper once

Input: a b b c d d I need: a c I know how to get this (the lines that have duplicates) : b d sort file | uniq -d But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Discussion started by: necroman08
3 Replies

10. UNIX for Dummies Questions & Answers

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... (3 Replies)
Discussion started by: reva
3 Replies
Login or Register to Ask a Question