awk two succeeding lines and moving matching files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk two succeeding lines and moving matching files
# 1  
Old 05-07-2014
Tools awk two succeeding lines and moving matching files

Hello everyone

I have a few hundreds of .mol2 files that has this pattern

Code:
 
    @<TRIPOS>ATOM
      2 H18 65.2220 Du 1 RES1 0.0000
    @<TRIPOS>BOND
     1  3  5  ar
    @<TRIPOS>SUBSTRUCTURE

among them, some of the files are missing the line after the @<TRIPOS>BOND and they look like

Code:
    @<TRIPOS>ATOM
      2 H18 65.2220 Du 1 RES1 0.0000
    @<TRIPOS>BOND
    @<TRIPOS>SUBSTRUCTURE

I'm trying to find all the files in my working directory that are missing the numeric line after the `@<TRIPOS>BOND` and move them to another directory. I know this is a simple task, but I am quite new to Linux.
Here's one of my codes, which I was planning to write in a for loop. It doesn't do the job, but I am showing it to show one of my trials.

Code:
for i in *.mol2; do cat $i | grep -A1 '@<TRIPOS>BOND' | awk 'FNR == 2 {print}' | awk '$1 ~ /^@/' ; done

I know my code is really inefficient, but I am not an expert with Lunix at all.

Appreciated.

Last edited by Error404; 05-07-2014 at 07:06 AM..
# 2  
Old 05-07-2014
One way


Code:
awk '/@<TRIPOS>BOND/ {getline;if ($0 ~ /@<TRIPOS>SUBSTRUCTURE/) {print FILENAME;exit}}' *.mol2


All it does is, checking for @<TRIPOS>SUBSTRUCTURE just after @<TRIPOS>BOND. If it finds, it will pass the criteria.
This User Gave Thanks to clx For This Post:
# 3  
Old 05-07-2014
perfect, I had to remove the 'exit' part to make it run for the whole directory. Thanks for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to average matching lines in file

The awk below executes and is close (producing the first 4 columns in desired). However, when I add the sum of $7, I get nothing returned. Basically, I am trying to combine all the matching $4 in f1 and output them with the average of $7 in each match. Thank you :). f1 ... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

awk to print matching lines in files that meet critera

In the tab delimited files below I am trying to match $2 in file1 to $2 of file2. If a match is found the awk checks $3 of file2 and if it is greater than 40% and $4 of file2 is greater than 49, the line in file1 is printed. In the desired output line3 of file1 is not printed because $3 off file2... (9 Replies)
Discussion started by: cmccabe
9 Replies

3. Shell Programming and Scripting

awk to combine matching lines in file

I am trying to combine all matching lines in the tab-delimited using awk. The below runs but no output results. Thank you :). input chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 47433390 47433999 SYN1... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

awk - matching on 2 columns for differents lines

Given this file (I separated them in block to make my explanation clearer): 92157768877;Sof_deme_Fort_Email_am_%yyyy%%mm%%dd%;EMAIL;20/02/2015;1;0;0 92157768877;Sof_trav_Fort_Email_am_%yyyy%%mm%%dd%;EMAIL;20/02/2015;1;0;0 91231838895;Sof_deme_faible_Email_am;EMAIL;26/01/2015;1 0;0... (1 Reply)
Discussion started by: Andy_K
1 Replies

5. Shell Programming and Scripting

Help With AWK Matching and Re-printing Lines

Hi All, I'm looking to use AWK to pattern match lines in XML file - Example patten for below sample would be /^<apple>/ The sample I wrote out is very basic compared to what I am actually working with but it will get me started I would like to keep the matched line(s) unchanged but have them... (4 Replies)
Discussion started by: rhoderidge
4 Replies

6. Shell Programming and Scripting

Look up between 2 files and print matching lines

Hi, I have 2 large log files in .gz format file 1 contains abcde 12345 23456 . . . . . . . . 09123 (8 Replies)
Discussion started by: aravindj80
8 Replies

7. Shell Programming and Scripting

Print lines matching value(s) in other file using awk

Hi, I have two comma separated files. I would like to see field 1 value of File1 exact match in field 2 of File2. If the value matches, then it should print matched lines from File2. I have achieved the results using cut, paste and egrep -f but I would like to use awk as it is efficient way and... (7 Replies)
Discussion started by: SBC
7 Replies

8. Shell Programming and Scripting

awk if statement matching all lines starting w/ a number

Does awk have a syntax for a range of numbers or is this the best way? if ($1 >= 0 && $1 <= 9 ) (7 Replies)
Discussion started by: Arsenalman
7 Replies

9. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

10. UNIX for Dummies Questions & Answers

Find matching lines between 2 files

How do I find matching lines between two files? (5 Replies)
Discussion started by: jojojmac5
5 Replies
Login or Register to Ask a Question