script to ensure lines are in sequence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to ensure lines are in sequence
# 1  
Old 05-30-2008
script to ensure lines are in sequence

Hello there,
I check files containing more than 2000 lines, I try to make sure that the lines are in sequence...for example the first line begins with Av567, second line contains Av568 and so on up to the last line that may contain Av2500.

I need a script to check that all lines are in sequence and if a line is skipped or not in sequence with the rest of the lines it tells me where is this line.

this will save me a lot of time, I'll be thankful for you if you can help
# 2  
Old 05-30-2008
A sample of some lines of your file would be helpful.

Regards
# 3  
Old 05-30-2008
awk:
Code:
>cat file
Av567 linea1
Av568 linea2
Av569 linea3
Av570 linea4
Code:
Av571 linea5
Code:
>awk '{gsub(/Av/,"",$1)
if ( NR ==1 ) 
   init=$1
else
   if ( $1 != init+NR-1 )
      {
      t=1
      print "Av"$0" : Not in sequence"
      exit
      }
}
END {
if (!t)
   print "Good sequence"
}'  file
Good sequence
Code:
>cat file
Av567 linea1
Av568 linea2
Av569 linea3
Av572 linea4
Av573 linea5
Code:
>awk '{gsub(/Av/,"",$1)
if ( NR ==1 ) 
   init=$1
else
   if ( $1 != init+NR-1 )
      {
      t=1
      print "Av"$0" : Not in sequence"
      exit
      }
}
END {
if (!t)
   print "Good sequence"
}'  file
Av572 linea4 : Not in sequence
Or in ksh: i=0 while read w1 r do n=${w1#Av} if (( i == 0 )) then init=$n else if (( n != ( init + i ) )) then echo "Not in sequence: $w1 $r" break fi fi (( i += 1 )) done<file

# 4  
Old 05-30-2008
sort -nc file perhaps?
# 5  
Old 05-30-2008
typeset -i line_no kine i ln
IFS="\n"
line_no=`cat Invalid_text.txt| awk '{print $1}'|cut -c2-4| tail -1`
i=567
cat Invalid_text.txt| awk '{print $1}'|cut -c2-4 > seq_tmp
ln=`cat seq_tmp |wc -l`
ctr=1
while [ $ctr -le $ln ]
do
line=`cat seq_tmp | head -$ctr |tail -1`
#[ $i -le $line_no ]

if [ $line -ne $i ]
then
echo "Sequence skipped. $i is not there"
fi
i=`expr $i + 1`
ctr=`expr $ctr + 1`
done
# 6  
Old 05-30-2008
Another bash or ksh solution :
Code:
while read avseq filler
do
   echo $avseq
   seq=${avseq#Av}
   while [ $seq -gt ${next_seq:=$seq} ]
   do
      echo "Missing sequence Av$next_seq"
      (( next_seq += 1 ))
   done


   if [ $seq -lt $next_seq ]
   then
      echo "Retrograde sequence  Av$seq"
   fi

   (( next_seq = seq + 1 ))
done < inputfile

Input file:
Code:
Av567 linea1
Av568 linea2
Av569 linea3
Av572 linea4
Av573 linea5
Av570 linea6
Av571 linea7

Ouput:
Code:
Av567
Av568
Av569
Av572
Missing sequence Av570
Missing sequence Av571
Av573
Av570
Retrograde sequence  Av570
Av571

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

2. Shell Programming and Scripting

How to ensure a script can only be invoked from another?

Hi All, I have two scripts - ScriptA and ScriptB ScriptA has logic to invoke ScriptB : - with some parameter - or without any parameter ScriptB can also be invoked by the user from the command line. Is there anyway to ensure that when I execute ScriptB from the command line, it does... (3 Replies)
Discussion started by: chaitanya.gvc
3 Replies

3. Programming

Ensure C++ will work on a Unix system

For my one college course, my professor said that we have to ensure that the C++ code we send him will work on a Unix system. I in turn installed Cygwin on my Windows 7 machine, and have been using that to compile and check my code, but it sounds like Cygwin is still compiling the code for my... (2 Replies)
Discussion started by: davidp007
2 Replies

4. Shell Programming and Scripting

filter out a sequence from multiple lines line

Hi, I have an unwanted string at random lines of my verilog (*.v) file. (* abccddee *) input A; (* xyz *) input B; (* 1234 *) output C; I want a clean file like this: input A; input B; output C; the unwanted string begins with "(*" and ends with "*)" at multiple lines. Any help... (2 Replies)
Discussion started by: return_user
2 Replies

5. AIX

How to ensure mksysb backup completed successfully.

Hi All, I want to know, how we can ensure that mksysb backup completed successfully and is restorable. I know one way my command lsmksysb -B but I found that one mksysb who has not backedup all the files was also showing in this command output, so that doesn't ensure its integrity and... (1 Reply)
Discussion started by: falgun6666
1 Replies

6. IP Networking

A test to ensure TCP/IP configuration is complete

Greetings. I have Debian lenny, and at the moment only the bare bones install, no GUI. I'm connecting via wireless to a Linksys router on a home network, and I manually configured a fixed ip etc during the install. I have not attempted to use any higher level apps such as ftp or telnet or apt yet.... (3 Replies)
Discussion started by: fguy
3 Replies

7. Shell Programming and Scripting

Ensure the file completion ?

Hi, I would like to copy a file from one location to another. But that particular file is not fully loaded. I like to copy a file once it's fully loaded or complete file. How to ensure whether file is fully loaded or complete file?. -Thambi (5 Replies)
Discussion started by: thambi
5 Replies

8. UNIX for Dummies Questions & Answers

Ensure FTP is complete before using file

Hi, I have a program that checks a directory for new files. A file may be placed in the directory only via FTP from another system. The files are long, the FTP can take several minutes to complete. my program sences that a file has arrived but can't tell if the FTP process that sent it is... (10 Replies)
Discussion started by: GMMike
10 Replies

9. Shell Programming and Scripting

How to extract a sequence of n lines from a file

Hi I want to be able to extract a sequence of n lines from a file. ideas, commands and suggestions would be highly appreciated. Thanks (4 Replies)
Discussion started by: 0ktalmagik
4 Replies
Login or Register to Ask a Question