Deleting column using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting column using awk
# 1  
Old 02-20-2012
Deleting column using awk

How Can we delete a range of coloumns using awk? (or any other method is fine)

If we have a file which has about 200 coloumns.
I need to delete a particular range lets say for eg from $6 to $119

Can we do this using cut, if yes the cut command would also be helpful.

many thanks in advance
Sri
# 2  
Old 02-20-2012
What have you tried so far?
# 3  
Old 02-20-2012
delete the columns from $3 to $5
Code:
[root@node2 ~]# echo {01..36} | xargs -n 6 
01 02 03 04 05 06
07 08 09 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36
[root@node2 ~]# echo {01..36} | xargs -n 6 | awk '{for(i=3; i<=5; ++i) $i=FS; print $0}'
01 02       06
07 08       12
13 14       18
19 20       24
25 26       30
31 32       36

# 4  
Old 02-21-2012
huaihaizi good reasoning
# 5  
Old 02-21-2012
Code:
echo {01..36} | xargs -n 6 | cut -d ' ' -f-2,6-

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

2. Shell Programming and Scripting

Deleting values in a column based on conditions

Hi I have a difficulty in writing shell script for performing the tasks. A B C D 12 230 16 259 18 260 23 283 21 291 36 298 41 309 49 420 52 425 57 450 61 456 70 473 72 475 79 486 If the A(row no.2) < C(row no.1) then delete value A(row no.1) and so on... For... (8 Replies)
Discussion started by: Sarwagya Jha
8 Replies

3. UNIX for Dummies Questions & Answers

Deleting rows where the value in a specific column match

Hi, I have a tab delimited text file where I want to delete all rows that have the same string for column 1. How do I go about doing that? Thanks! Example Input: aa 1 aa 2 aa 3 bb 4 bc 5 bb 6 cd 8 Output: bc 5 cd 8 (4 Replies)
Discussion started by: evelibertine
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

5. Shell Programming and Scripting

Deleting the first column with sed,awk or perl

336 brtr 256 hello Output: brtr hello How can i do this with sed,awk or perl? (5 Replies)
Discussion started by: cola
5 Replies

6. UNIX for Dummies Questions & Answers

deleting a row if a certain column is below a certain number

How can you delete a row if a certain column is bigger than a certain number? I have the following input: 20080709 20081222 95750 1 0 0.02 94.88 20080709 20081222 95750 2 0 0.89 94.88 20080709 20081222 9575 1 0 0 94.88 20080709 20081222 9575 2 0 0 94.88 20080709 20081222 9587.5 1 0 0... (6 Replies)
Discussion started by: Pep Puigvert
6 Replies

7. UNIX for Dummies Questions & Answers

deleting a row if a certain column is below a certain number

How can you delete a row if a certain column is bigger than a certain number? I have the following input: 20080709 20081222 95750 1 0 0.02 94.88 20080709 20081222 95750 2 0 0.89 94.88 20080709 20081222 9575 1 0 0 94.88 20080709 20081222 9575 2 0 0 94.88 20080709 20081222 9587.5 1 0 0... (1 Reply)
Discussion started by: Pep Puigvert
1 Replies

8. Shell Programming and Scripting

Deleting repeated strings in column 2

Hi to all, I have a file where the subject could contain "Summarized Availability Report" or only "Summarized Report" If the subject is "Summarized Availability Report" I want to apply it Scrip1 and if the subject is "Summarized Report" I want to apply it Scrip2. 1-) I would like you... (5 Replies)
Discussion started by: cgkmal
5 Replies

9. Shell Programming and Scripting

Deleting column from a flatfile with delimiter

I have a set of flatfiles which have columns delimited by #. How can a particular column be deleted in all the flatfiles. All flatfiles have same number of columns. (5 Replies)
Discussion started by: rsprabha
5 Replies
Login or Register to Ask a Question