LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-30-2008, 04:13 AM   #1
docaia
LQ Newbie
 
Registered: Jan 2008
Posts: 18

Rep: Reputation: 0
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
 
Old 05-30-2008, 04:41 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
What if you just use like 'sort -nrk1 <file>'?
 
Old 05-30-2008, 05:10 AM   #3
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
I can hardly script these days
I cobbled this together after several brief visits to tldp:
Code:
#!/bin/bash
#usage: ./script-name <file-name

#assuming count starts from Av102:
check=102

# read each line till eof:
while read line
do
    #assuming Avxxx is the first column of each line:
    test=$(echo $line | awk '{print $1}' | cut -c3-)
    if [ $test != $check ]
    then
        echo "Error! $check is missing!"
        break
    fi
    check=$(expr 1 + $check)
done
My file is called temp.sh and I made a temporary test file called temp.txt with these contents:
Code:
Av102  blah
Av103 blahblah
Av104 blah
Av106 blh
Av107 asdf
Av108 asdfasdf
When I run it, this is what I get in the output (note that I'm passing the contents of temp.txt, not just the filename, i.e <temp.txt:
Code:
bash-2.05b ~/scrap$ ./test.sh <temp.txt
Error! 105 is missing!
bash-2.05b ~/scrap$
Now I'll wait for someone to post a perl one-liner that does the same thing..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help adding a script to shutdown sequence trapix22 Linux - Newbie 1 12-29-2007 01:08 AM
How to ensure that a script start before kde starts? adityavpratap Slackware 3 06-03-2007 03:42 AM
Help to remove script from booting sequence sasha_baranov Linux - Newbie 1 11-18-2004 09:34 AM
removing lines from file script iluvatar Programming 9 08-20-2004 05:49 AM
Replace lines in script AMMullan Linux - Software 9 12-06-2003 11:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration