Delete column with exact string in specific col


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete column with exact string in specific col
# 1  
Old 06-28-2013
Delete column with exact string in specific col

Hi,
my file structur looks like
Code:
File structure looks:
GeneID protein_gi Symbol
1246500 10954455 repA1
1246501 10954457 repA2
1246502 10954458 leuA

But some of the cases do not have record for protein id. for example:
Code:
1343044 - orf01

I want to remove those rows.

But I tried
Code:
awk -F, '$2==!/-/' file.txt >test1.txt 
awk -F' ', '$2==!/-/' file.txt >test1.txt

None of them are working.
Can anybody please help? Thanks a lot,Mitra

---------- Post updated at 06:51 AM ---------- Previous update was at 06:48 AM ----------

I also tried
Code:
awk -F' ', '$2=='-'' file.txt >test1.txt

But got error like
Code:
awk: syntax error at source line 1
 context is
	 >>>  <<< 
awk: bailing out at source line 1


Last edited by smitra; 06-28-2013 at 02:51 AM.. Reason: typo error
# 2  
Old 06-28-2013
try this

Code:
awk '{if ($2!="-") print}' file.txt

or


Code:
awk '$2!="-" {print} ' file.txt


Last edited by krishmaths; 06-28-2013 at 03:03 AM.. Reason: Added alternative solution
This User Gave Thanks to krishmaths For This Post:
# 3  
Old 06-28-2013
Is your file comma seperated? if space seperated..

Code:
 
awk '$2 ~ !/-/{print $0}' filename

This User Gave Thanks to vidyadhar85 For This Post:
# 4  
Old 06-28-2013
Code:
grep -v "\-" file

These 2 Users Gave Thanks to Just Ice For This Post:
# 5  
Old 06-28-2013
Thanks a lot all for your help. It worked perfectly with krishmath and vidyadhar85's suggestions...
Just Ice, thanks to you also, but as I have "-" in 3rd Gene symbol col also sometimes, thus I prefer to use column number.
Thanks a lot to all again. Smilie

---------- Post updated at 07:38 AM ---------- Previous update was at 07:20 AM ----------

Hello all,
Can anybody suggest me why the new file sizes created by all above commands differ? only first two are identical with awk...
Code:
awk '{if ($2!="-") print}' file.txt

or
Code:
awk '$2!="-" {print} ' file.txt

But with
Code:
awk '$2 ~ !/-/{print $0}' filename

and
Code:
grep -v "\-" file

provide different file size... I am comparing as my input file is same, and for this occasion I have no '-' in other cols.

Any suggestion whould be good.
Thanks,
Mitra
# 6  
Old 06-28-2013
Quote:
Originally Posted by smitra
Thanks a lot all for your help. It worked perfectly with krishmath and vidyadhar85's suggestions...
Just Ice, thanks to you also, but as I have "-" in 3rd Gene symbol col also sometimes, thus I prefer to use column number.
Thanks a lot to all again. Smilie

---------- Post updated at 07:38 AM ---------- Previous update was at 07:20 AM ----------

Hello all,
Can anybody suggest me why the new file sizes created by all above commands differ? only first two are identical with awk...
Code:
awk '{if ($2!="-") print}' file.txt

or
Code:
awk '$2!="-" {print} ' file.txt

But with
Code:
awk '$2 ~ !/-/{print $0}' filename

and
Code:
grep -v "\-" file

provide different file size... I am comparing as my input file is same, and for this occasion I have no '-' in other cols.

Any suggestion whould be good.
Thanks,
Mitra
I guess the below command stops printing after it encounters a "-" in 2nd column.
Code:
awk '$2 ~ !/-/{print $0}' filename

The
Code:
grep -v

should work fine. Are you sure you don't have any other "-" in the file?
This User Gave Thanks to krishmaths For This Post:
# 7  
Old 06-28-2013
Thanks krishmaths,
Yes I guess that is the case. As first two commands deliver the file with size >300MB
But other just over 200MB.

No I am not sure..in some cases files may have - in other cols...thus I also prefer $2!="-"
Thanks for explaining.
Mitra.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete lines starting with specific string?

Dear all, I would like to delete even lines starting with "N" together with their respective titles which are actually odd lines. Below is the example of input file. I would like to remove line 8 and 12 together with its title line, i.e., line 7 and 11, respectively.... (2 Replies)
Discussion started by: huiyee1
2 Replies

2. Shell Programming and Scripting

Print lines that contain a value in a specific column shared by more than 1 entity in another col

I want to expand on a question that I just asked here: I want to extract only those values in Column 2 that are shared by at least 2 unique values in Column 2. Using the same input (in this case 3- tab-separated columns): waterline-n below-sheath-v 14.8097 dock-n below-sheath-v ... (2 Replies)
Discussion started by: owwow14
2 Replies

3. UNIX for Dummies Questions & Answers

Delete rows with unique value for specific column

Hi all I have a file which looks like this 1234|1|Jon|some text|some text 1234|2|Jon|some text|some text 3453|5|Jon|some text|some text 6533|2|Kate|some text|some text 4567|3|Chris|some text|some text 4567|4|Maggie|some text|some text 8764|6|Maggie|some text|some text My third column is my... (9 Replies)
Discussion started by: A-V
9 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

Sed find exact string and delete line with variable

All, I am trying to read in a variable and search a file then delete based on that string, but i want to match exact word. This works but it matches all, i don't want to match anthing that contains the string, just the exact string. sed -i "/$feedname/d" file I tried sed... (1 Reply)
Discussion started by: markdjones82
1 Replies

6. Shell Programming and Scripting

delete a row with a specific value at a certain column

Hi, I want to delete rows that have 0 at column 4. The file looks like this: chr01 13 61 2 chr01 65 153 0 chr01 157 309 1 chr01 313 309 0 chr01 317 469 1 chr01 473 557 0 I want to delete all rows with a 0 at column 4 chr01 13 61 2 chr01 157 309 1 chr01 ... (3 Replies)
Discussion started by: kylle345
3 Replies

7. UNIX for Dummies Questions & Answers

Delete all rows that contain a specific string (text)

Hi, I have a text file and I want to delete all rows that contain a particular string of characters. How do I go about doing that? Thanks! (9 Replies)
Discussion started by: evelibertine
9 Replies

8. UNIX for Dummies Questions & Answers

Delete a specific column using vi editor?

Hello Experts, I'm a newbie so please excuse any wrong doings. I have a file that looks like this. abc def ghi jkl mno def abc ghi mno jkl ghi def mno jkl abc I would like the file to look like this abc def ghi jklmno def abc ghi mnojkl ghi def mno jklabc in other... (3 Replies)
Discussion started by: fnebiolo
3 Replies

9. Shell Programming and Scripting

delete empty spaces at specific column

Hi All, If anybody could help me with my scenario here. I have a statement file. Example of some content: DATE DESC Debit Credit Total Rate 02-Jan-08 Lodgement 200.00 1200.00 2.51 14-Sep-07 Withdrawal 50.00 1000.00 ... (8 Replies)
Discussion started by: yonez
8 Replies

10. Shell Programming and Scripting

delete strings till specific string

Hello i want to know a way so i can delete all the strings in file from the begning till a specific string (1 Reply)
Discussion started by: modcan
1 Replies
Login or Register to Ask a Question