Deleting lines that contain a specific string from a space delimited text file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting lines that contain a specific string from a space delimited text file?
# 1  
Old 08-22-2011
Deleting lines that contain a specific string from a space delimited text file?

Hi,

I have a space delimited text file that looks like the following:


250 rs10000056 0.04 0.0888 4 189321617
250 rs10000062 0.05 0.0435 4 5254744
250 rs10000064 0.02 0.2403 4 127809621
250 rs10000068 0.01 NA
250 rs1000007 0.00 0.9531 2 237752054
250 rs10000081 0.03 0.1400 4 17348363
250 rs10000085 0.01 0.3630 4 61435320
250 rs10000088 0.01 NA
250 rs10000092 0.00 0.8284 4 21895517
250 rs1000012 0.00 0.6633 9 135703041
250 rs10000121 0.00 0.6653 4 157574035
250 rs10000132 0.00 0.9437 4 7399669

I would like to remove all the lines that contain NA. How do I go about doing that? Thanks!
# 2  
Old 08-22-2011
Code:
egrep -v 'NA' File

# 3  
Old 08-22-2011
Code:
grep -v NA infile > outfile

# 4  
Old 08-22-2011
Assuming a space in front and it's at the end of a line:
Code:
sed '/ NA$/d'  inputfilename > outputfilename

# 5  
Old 08-23-2011
Code:
 
awk ' ! /NA/ {print $0}' input > output

# 6  
Old 08-23-2011
Wow. It even works. Smilie
Code:
require.paths.unshift('/usr/local/lib/node_modules');
var Lazy=require("lazy");

new Lazy(process.stdin)
    .lines
    .forEach(
	function(line) 
	{ 
            var s = line.toString();
	    if (! s.match(/NA/)) console.log(s); 
	}
    );

process.stdin.resume();

Code:
sudo npm -g install lazy
...
node select.js <INPUTFILE
...

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting specific lines from text file via scripting

Hi, I'm trying to search for some number and from that line, i need to delete the 5th line exactly. Eg: Consider below as text file data: 10000 a b c d e . . . 10000 w q t (8 Replies)
Discussion started by: Gautham
8 Replies

2. Shell Programming and Scripting

Issue deleting all lines (having a specific string) in a file

I'm trying to create a script. There are 2 files - fileA.log & fileB.log fileA.log has the below data : aaaa cccc eeee fileB.log has the below data : cjahdskjah aaaa xyz jhaskjdhas bbbb abc ajdhjkh cccc abc cjahdskjah ... (7 Replies)
Discussion started by: Pandee
7 Replies

3. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

4. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

6. UNIX for Dummies Questions & Answers

Deleting columns from a tab delimited text file?

I have a tab limited text file with 10000+ columns. I want to delete columns 6 through 23, how do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. UNIX for Dummies Questions & Answers

How do you view specific columns from a space delimited text file?

I have a space delimited text file with 1,000,000+ columns? I would only like to view specific ones (let's say through 1:10), how can I do that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

8. UNIX for Dummies Questions & Answers

Deleting cells that contain a specific number only from a space delimited text file

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 cells that consist of just 2 (leave 2's that are not by themselves intact): File before modification aa bb cc 2 NA100 dd aa b1 c2 2 NA102 de File after modification... (1 Reply)
Discussion started by: evelibertine
1 Replies

9. UNIX for Dummies Questions & Answers

Deleting columns from a space delimited text file

I have a space delimited text file with 1,000,000+ columns and 100 rows. I want to delete columns 2 through 5 (2 and 5) included from the text file. How do I do that? Thanks. (3 Replies)
Discussion started by: evelibertine
3 Replies

10. UNIX for Dummies Questions & Answers

deleting lines from a delimited files based on a 2nd file

I need a little help... I have a file with 3 fields, Time/Date, IP address, UniqueID I have a 2nd file of UniqueIDs. I want to either (which ever is easier): 1. delete entries in file 1 that have a UniqueID in file 2 2. create a new file with the fields from File 1, excluding the... (4 Replies)
Discussion started by: goldie363
4 Replies
Login or Register to Ask a Question