How to delete all columns that start with a specific value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to delete all columns that start with a specific value
# 1  
Old 05-31-2011
How to delete all columns that start with a specific value

I have this space delimited large text file with more than 1,000,000+ columns and about 100 rows. I want to delete all the columns that start with NA such that:

File before modification
aa bb cc NA100 dd
aa b1 c2 NA101 de

File after modification
aa bb cc dd
aa b1 c2 de

How would I delete all the columns/cells that start with NA? Thanks.
# 2  
Old 05-31-2011
Try:
Code:
perl -pe 's/ NA[^ ]+//g' file

# 3  
Old 05-31-2011
What if the cells that I want to delete specifically contain " 2 " by itself? There are other 2's elsewhere in the document but I specifically want to delete the cells that only contain 2.
# 4  
Old 06-01-2011
Code:
perl -pe 's/ 2 / /g' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

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

3. Shell Programming and Scripting

Convert row to columns start from nth column

Dear All, We have input like this: 161 57 1378 176 1392 262 1444 441 1548 538 1611 670 1684 241 57 1378 208 1393 269 1447 444 1549 538 1610 677 1700 321 ... (4 Replies)
Discussion started by: attila
4 Replies

4. UNIX for Dummies Questions & Answers

Printing lines with specific strings at specific columns

Hi I have a file which is tab-delimited. Now, I'd like to print the lines which have "chr6" string in both first and second columns. Could anybody help? (3 Replies)
Discussion started by: a_bahreini
3 Replies

5. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

6. Shell Programming and Scripting

Put a # in start of a specific line of a file

Hello Guys Please let me know how to solve the below issue I have a file like below drop table R1416.ABC1 cascade constraints; drop table R1416.ABC2 cascade constraints; drop table R1416.ABC3 cascade constraints; drop table R1416.ABC4 cascade constraints; drop table R1416.ABC5... (7 Replies)
Discussion started by: Pratik4891
7 Replies

7. Shell Programming and Scripting

Start from the prefixes, delete script

My folder is/app2/istech/scratch, which contain all the below files. I need to delete the files which start from the prefixes. dup_events_*.* Event_*.* New_time_*.* New_Loc_*.* New_Uptime_*.* Detailed_Reason*.* cmt_dup_*.* Uptime_*.* Can anyone please let me know how to write a... (3 Replies)
Discussion started by: dsnaveen
3 Replies

8. Shell Programming and Scripting

Delete all lines that start with a bigger number of a specific one.

E.g. the file is like this: I want to delete all lines that begin with a number larger than 2, ignoring the lines that doesn't begin with a number! PS:'2' is actually a variable that can have a lot of values:b:i bet you got it (10 Replies)
Discussion started by: hakermania
10 Replies

9. Shell Programming and Scripting

need to delete lines that start with letters

Hi, I need to remove all lines from a file that do not start with numbers For instance, if the first three characters on any line are not numbers, delete those lines I've tried to do it with awk and it's not working, any ideas ? Thanks (5 Replies)
Discussion started by: sfisk
5 Replies
Login or Register to Ask a Question