awk remove column with conditions?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk remove column with conditions?
# 1  
Old 04-24-2009
awk remove column with conditions?

Folks:

I have a file which has 3 columns. Using awk I want to remove rows from column 3 (Col3 <> A) where it is not equal to A. All columns are seperated by "|".

Col1|Col2|Col3|Col4
1 | 2 | A | 4
2 | 3 | A | 5
3 | 4 | B | 6
4 | 5 | A | 7
5 | 6 | B | 8
6 | 7 | A | 9

Last edited by pr2003; 04-24-2009 at 01:01 PM..
# 2  
Old 04-24-2009
what's the desired output given a sample input?
# 3  
Old 04-24-2009
awk remove column with conditions?

The output should be: I am newbie so I need the awk script which will give me this output so that I can automate the process.

Col1|Col2|Col3|Col4
3 | 4 | B | 6
5 | 6 | B | 8

Last edited by pr2003; 04-24-2009 at 02:36 PM..
# 4  
Old 04-24-2009
Code:
nawk -F'|' '$3 != "A"' OFS='|' myFile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk to remove specific column to one range

I need to remove specific column to one range source file 3 1 000123456 2 2 000123569 3 3 000123564 12 000123156 15 000125648 128 000125648 Output required 3 000123456 2 000123569 3 000123564 12 000123156 15 000125648 128 000125648 (6 Replies)
Discussion started by: ranjancom2000
6 Replies

2. Shell Programming and Scripting

How can I remove first column with awk?

cat input.txt a x b y c z Expected output x y z (11 Replies)
Discussion started by: cola
11 Replies

3. Shell Programming and Scripting

Create new file with increment column based on conditions

Hello, Using bash script, i need to process the following file: 887,86,,2013-11-06,1,10030,5,2,0,200,, 887,86,,2013-11-05,1,10030,5,2,0,199,, 887,138,,2013-11-06,1,10031,6,2,0,1610612736,, 887,164,,2013-11-06,1,10000,0,2,0,36000,, and to create a new file such as the below ... (2 Replies)
Discussion started by: JonhyDeep
2 Replies

4. Shell Programming and Scripting

Use grep/awk to remove part of column

hi all, how can i use grep or awk to clean the following input data: n<>the<>96427210 861521305 123257583 n<>obj<>79634223 861521305 79634223 n<>nmod<>68404733 861521305 68422718 where the desired results is to remove all non-numeric characters?: 96427210 861521305 123257583 ... (5 Replies)
Discussion started by: owwow14
5 Replies

5. Shell Programming and Scripting

Remove Specific Column in a File using awk

Hi, I would like to ask your expertise to remove specific column no. 8 in the below file using but I don't have an idea on how to simply do this using awk command. Appreciate your help in advance. Input f: ABC 1 1XC CDA 1 2YC CCC 1 3XC AVD 1 3XA Expected output file: ABC 1 1C CDA... (9 Replies)
Discussion started by: zzavilz
9 Replies

6. UNIX for Dummies Questions & Answers

awk to remove redundancy, with conditions

Hi Everyone, I've been using awk '!x++' to get rid of redundancy in a file, but it's getting rid of some extra lines I need (like the plus signs in the example below). So how would I go from this: @XYZ ABCD 345345 + @MNO EFGH 789789 + @XYZ ABCD 345345 + to: (2 Replies)
Discussion started by: sp24
2 Replies

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

8. Shell Programming and Scripting

awk : Remove column1 and last column in a line

Hi All, How to remove col1 and last column in a line. Please suggest some awk stuffs. Input col1 col2 col3 col4 col1 col2 col3 col4 col5 col1 col2 col3 col4 col1 col2 col3 Output Processing col2 col3 ... Processing col2 col3 col4 ... Processing col2 col3 ... Processing... (5 Replies)
Discussion started by: k_manimuthu
5 Replies

9. UNIX for Dummies Questions & Answers

How to get remove duplicate of a file based on many conditions

Hii Friends.. I have a huge set of data stored in a file.Which is as shown below a.dat: RAO 1869 12 19 0 0 0.00 17.9000 82.3000 10.0 0 0.00 0 3.70 0.00 0.00 0 0.00 3.70 4 NULL LEE 1870 4 11 1 0 0.00 30.0000 99.0000 0.0 0 0.00 0 0.00 0.00 0.00 0 ... (3 Replies)
Discussion started by: reva
3 Replies

10. Shell Programming and Scripting

Remove certain parameters from column using awk or sed

I have a text file Nov 1 LOG_10_000000343.gzip_COMPLETE 2910 server.log.3 Nov 4 LOG_10_000000343.gzip_COMPLETE 2910 server.log.4 Dec 5 LOG_10_000000343.gzip_blah 2910 server.log.5 Jul 6 LOG_10_000000343.gzip_ERROR 2910 server.log.1 I need to convert this to Nov 1 LOG_10_000000343.gzip... (3 Replies)
Discussion started by: gubbu
3 Replies
Login or Register to Ask a Question