Error removed from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error removed from file
# 8  
Old 03-22-2015
The user inputs the variant(s) and those two inputs are checked and the output is written to a file ${id}_name.txt. In that file after the header row is skipped in $3 if the text (variantchecker): is there an error has occurred and in $1 the text will match in the file ${id}.txt. When a match is found it is removed from the file. Thank you Smilie.

So using the attached files from post 1 as an example:


The header of ${id}_name is skipped and there is an error in line 2 (indicated by the (variantchecker): in $3) in the first variant and $1 (NM_004004.5:c.74G>C) matches $1 of ${id).txt, that variant is removed from the ${id}.txt file.

I am trying to achieve this and the awk was my attempt.

Last edited by cmccabe; 03-22-2015 at 10:44 AM..
# 9  
Old 03-23-2015
Maybe this awk ?

Code:
 awk '{if (f==1) { r[$3] } else if (! ($3 in r)) { print $1 } } ' f=1 ${id}_name.txt f=2 $(id}.txt

Thank you Smilie.
# 10  
Old 03-23-2015
I don't think there's a $3 in the second file.

How about
Code:
awk '/variantchecker/ {r[$1]} FNR==NR {next} !($1 in r)' /tmp/GJB2_name.txt /tmp/GJB2.txt
NM_004004.5:c.283G>T

# 11  
Old 03-23-2015
The code below runs, but the variant that had an error in it is still in the file,

Code:
 check() {
    printf "\n\n"
	awk 'NR>1 { if ($2 ~ /^\(/ ) {$1=""; print "Found error: ", $0} else { sub(/.*:/, "", $1); sub(/.*:/, "", $7); print "No error: " $1 "," $7}}' C:/Users/cmccabe/Desktop/Python27/${id}_name.txt
	printf "Is the variant correct?  Y/N "; read match_choice
	
    case "$match_choice" in
        [yY]) id="${id}"; additionalg ;; 
        [nN]) cd 'C:/Users/cmccabe/Desktop/Python27/' awk '/variantchecker/ {r[$1]} FNR==NR {next} !($1 in r)' ${id}_name.txt ${id}.txt; gjb2 ;;  
    esac
}

Code:
 
Found error:   (variantchecker): G not found at position 289, found T instead.
No error: c.79G>A,p.(Val27Ile)
Is the variant correct?  Y/N

Thank you Smilie.
# 12  
Old 03-23-2015
Where's the semicolon between cd and awk?
# 13  
Old 03-23-2015
Tried with and w/o " " and got the same error but I see the file in the directory it says is not there. Thank you Smilie.

Code:
 check() {
    printf "\n\n"
	awk 'NR>1 { if ($2 ~ /^\(/ ) {$1=""; print "Found error: ", $0} else { sub(/.*:/, "", $1); sub(/.*:/, "", $7); print "No error: " $1 "," $7}}' C:/Users/cmccabe/Desktop/Python27/${id}_name.txt
	printf "Is the variant correct?  Y/N "; read match_choice
	
    case "$match_choice" in
        [yY]) id="${id}"; additionalg ;; 
        [nN]) cd 'C:' C:/Users/cmccabe/Desktop/Python27/; awk '/variantchecker/ {r[$1]} FNR==NR {next} !($1 in r)' "${id}"_name.txt "${id}".txt; gjb2 ;;  
    esac
}

Code:
 
Found error:   (variantchecker): G not found at position 289, found T instead.
Is the variant correct?  Y/N n
awk: fatal: cannot open file `gj_name.txt' for reading (No such file or director
y)

# 14  
Old 03-23-2015
The command runs now, it just needed the path, however both variants are in the file.

For example, in the attached output NM_004004.5:c.74G>A is an error and remains in the file even after the user inputs the correct variant
NM_004004.5:c.79G>A
.

Here is the command, though I'm sure it can be written better (I see some things I will change tomorrow). I.m reading the awk manual as you suggested.

Code:
 check() {
    printf "\n\n"
	awk 'NR>1 { if ($2 ~ /^\(/ ) {$1=""; print "Found error: ", $0} else { sub(/.*:/, "", $1); sub(/.*:/, "", $7); print "No error: " $1 "," $7}}' C:/Users/cmccabe/Desktop/Python27/${id}_name.txt
	printf "Is the variant correct?  Y/N "; read match_choice
	
    case "$match_choice" in
        [yY]) id="${id}"; additionalg ;; 
        [nN]) id="$id"; cd 'C:' C:/Users/cmccabe/Desktop/Python27/; awk '/variantchecker/ {r[$1]} FNR==NR {next} !($1 in r)' C:/Users/cmccabe/Desktop/Python27/${id}_name.txt C:/Users/cmccabe/Desktop/Python27/${id}.txt; gjb2 ;;
    esac
}

Thank you for all your helpSmilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recover the original file once removed

Hi All, Is there is any machanisim, once delete the file can we restore it. Thanks (8 Replies)
Discussion started by: bmk123
8 Replies

2. UNIX for Beginners Questions & Answers

File Management: Removing of files from Server2 IF the same file is removed from Server1.

Hi Folks, I have a requirement of file management on different servers. Source Server is SERVER-A. Two servers will fetch files from SERVER-A: SERVER1 and SERVER2. 4th SERVER is SERVER-B, It will fetch files from SERVER1. If SERVER1 goes DOWN, SERVER-B will fetch pending files from... (2 Replies)
Discussion started by: Raza Ali
2 Replies

3. UNIX for Beginners Questions & Answers

File Containing Extra delimiter should be removed

The input file is this: a|b|c|d x|y|z|n||||||||| p|q|r|s||| g|h|i| w|e|r|| Now as per requirement , each row should have only 3 delimiter. Now the 2nd row & last row has an extra delimiter, How to remove that ? In some large file having 100K data , there can be 100 such rows having... (4 Replies)
Discussion started by: ikdKunal
4 Replies

4. Solaris

File system full - not removed: No space left on device

Does anyone have any advise on trying to clean up a full filesystem? I can't rm any files because of the follow: not removed: No space left on device Any help would be very much appreciated. (10 Replies)
Discussion started by: craigsky
10 Replies

5. Programming

The fwrite function is not returning error, if the file was removed.

The fwrite function call is not returning error, when the file it writes to is removed, please advise on how to find if the file already opened and being written by a program is removed manually or by some other process. please see the code below, #include<stdio.h> #include<stdlib.h> ... (3 Replies)
Discussion started by: Kesavan
3 Replies

6. Red Hat

How to update rpm database regarding removed file of a package?

For Suppose, I have installed a package having files file1, file2 and file3. After installation, I removed the file "file3". But "rpm -qf file3" is giving the package name, even file3 was not there. And also "rpm -ql package" is also displaying all 3 files. How can i update rpm database about... (6 Replies)
Discussion started by: snreddy_gopu
6 Replies

7. Linux

file removed

Hi Team, I have deleted a file accidentally by using rm command. I am not the root(admin) user. Can you please let me know how to get that .tex file? (2 Replies)
Discussion started by: darling
2 Replies

8. UNIX for Dummies Questions & Answers

how to removed chr(10) characters in a file

Hi, How do we remove an extra new line in a file. New line in ascii is called chr(10). Suppose we have a file as: 12345 98765 ------ ------ From the above i represented new line with dashed lines. Basically i have 2 new lines with white space at the end of the file. How do i removes... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

9. Shell Programming and Scripting

Please Help. Strings in file 1 need to be searched and removed from file 2

Please help. Here is my problem. I have 9000 lines in file a and 500,000 lines in file b. For each line in file a I need to search file b and remove that line. I am currently using the grep -v command and loading the output into a new file. However, because of the size of file b this takes an... (4 Replies)
Discussion started by: mjs3221
4 Replies

10. Solaris

after init all /tmp file has been removed

I'm new in Solaris server After the system support reboot the Solaris server, all the files in /tmp has been removed, is that normal under Solaris or under different init level will get different result? which init level will do that? (5 Replies)
Discussion started by: yesthomas
5 Replies
Login or Register to Ask a Question