Tricky Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tricky Shell script
# 1  
Old 08-10-2007
MySQL Shell Script for the following problem

The Problem is mentioned below

Last edited by namishtiwari; 08-11-2007 at 09:31 AM..
# 2  
Old 08-10-2007
MySQL

The format of the data will be like this

00,11,21,00,00,55,00,73,83,07,00,22,39,43,00,66,00,00,00,15,00,00,44,58,67,00,87
02,14,24,30,00,00,00,70,00,00,00,00,32,47,50,60,74,00,04,16,27,38,00,00,00,00,89
00,00,00,00,42,52,61,71,86,01,00,29,33,00,59,00,75,00,03,19,00,00,45,00,68,00,88
00,13,20,31,00,00,64,76,00,05,00,00,35,41,56,00,00,81,00,00,28,00,00,57,65,79,90
06,10,00,36,40,00,00,00,80,00,12,25,00,00,51,62,72,00,09,00,00,37,49,00,69,00,84
00,17,23,00,46,53,00,77,00,08,00,00,34,00,54,00,78,82,00,18,26,00,48,00,63,00,85
00,14,23,39,00,00,60,00,87,02,00,28,00,41,50,00,75,00,03,15,00,00,44,00,68,00,90
00,16,25,35,00,53,00,71,00,08,00,00,36,40,00,62,00,88,00,00,27,37,00,58,64,78,00
05,10,00,00,48,52,00,73,00,00,00,24,31,00,57,66,00,81,07,17,00,00,49,00,00,79,85
00,00,20,33,00,00,63,70,80,06,12,00,34,42,56,00,00,00,00,00,29,00,00,59,69,74,86
04,13,00,32,43,00,65,00,00,00,18,22,00,00,55,00,72,84,09,00,00,38,47,00,67,00,89
01,11,21,00,00,51,00,76,00,00,00,26,30,45,54,00,00,82,00,19,00,00,46,00,61,77,83
06,11,22,00,00,00,64,00,81,00,00,00,30,40,56,00,79,85,08,15,27,35,00,59,00,00,00
# 3  
Old 08-11-2007
MySQL

[QUOTE=mike_bike_kite]I count 27 entries on every line.
Right,but the ticket format which i pasted earlier we need to follow that,
yes there are 27entries but ,in a row there are 9 columns and exactly 5 entries should be there not more than that.
In a column there should be min 1 entry and that only should be in ascending order.


00 appears ten times on the first line.
We need not to consider 00 for this problem they are just to fill fields,ignore that.

I count 27 entries on every line.
If bunches of these group up into a single entry then how does 27 split into 5 entries?
27 split into 15entries rest are put as zero but neglect that entries.

The last column of figures doesn't do this.
That is what we need to check.

So what have you done so far - perhaps we can work it out from that :S
Now you are clear of the problem or need some more explanation.

Thanks for the comments.
# 4  
Old 08-11-2007
MySQL Tricky Shell script

I have to write a shell script for the following problem.I am a novice in this area.Please help me out all Guru's.

02 00 00 34 41 00 00 70 81
00 14 20 37 00 53 63 00 00
09 18 23 00 45 00 00 79 00

I have to write a shell script like this...

1. In a row there are 9 entries but there should be exactly 5 entries in a row.
We need to neglect 00 they are just to fill the positions but of no use so ignore them.,

2. In a column there should be minimum 1 entry and if more than that then in ascending order only.

3. There should be total 15 entries in all even though thare are 27 but 00 a need not be considered they are just to fill the positions.

If you have any doubt please let me know.
I will appericiate your help in this regard.

Thanks in Advance
Namish
# 5  
Old 08-11-2007
is it home work
# 6  
Old 08-11-2007
I think you have opened mutiple threads for this which is against the forum rules.
# 7  
Old 08-11-2007
MySQL

I have the following script written for this,as i told i am novice in this shell scripting field so i need some guidance,There are erros when i ran the script but its hard for me to track them.

Code:
       echo "enter the file name"
       read file
       k=1
       n=1,o=10,p=19
       for firstline in $file
       do
       firstline = `sed -n $k p $file`
       num1 = `cut -f$n -d "," -s $firstline` 
       num2 = `cut -f$o -d "," -s $firstline`
       num3 = `cut -f$p -d "," -s $firstline`

        
      if [ $num1 -lt $num2 && $num1 -lt $num3 && $num2 -lt $num3 ]
       then
       echo " Numbers in column are in ascending order"
        else
          echo " Numbers not in ascending order in columns"
          n = `expr $n + 1`
          o = `expr $o + 1`
          p = `expr $p + 1`
      fi

        echo " To check the total numbers in a row "
        for a in firstline
         do
          a = `cut -f1-9 -d  "," -s $firstline`
          count=0
          digits = `grep [0-9][1-9] a`
           count = `expr $count + 1`
           echo " The total number of digits in a row is $count "
           done
     k = `expr $k + 1`
 
     echo "To check total numbers in an entry"

       for tdigits in firstlineline
        do
         count=0
         tdigits = `grep [0-9][1-9] firstline`
         echo "The total Numbers of digits are $count"
         count = `expr $count + 1`
         done
        echo " We have completed the task,at the end of program"
 done

[/quote]

Last edited by namishtiwari; 08-11-2007 at 09:29 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing xml - tricky one...need help!!

Hi, i am new to linux programming fraternity but looks like starting with a big thing... yes..xml parsing (it is indeed tough for a beginner like me) so need your kind help... The snippet of xml looks like: <snapshot> <tag1> <key>1234</key> <keytype>abcd</keytype> </tag1> <tag2>... (11 Replies)
Discussion started by: rookie2014
11 Replies

2. Shell Programming and Scripting

Tricky sed required

Hi All I need to put some sed together for a task and its a bit advanced for me, so I thought I'd ask if anyone here could help. I have a csv file with content like this - "","abcde","","" "'","abcde","","" "","","","1234" "'e'","","","" I need to remove any single quotes that fall... (17 Replies)
Discussion started by: steadyonabix
17 Replies

3. Solaris

Tricky egrep

Hi folks! My first post here. I'm working on a script that retrieves a range of files from a list depending on a range of time. UPDATE: I've seen it could be difficult to read all this thing, so I'll make a summarize it.. How come I do this and take a result.. grep "..\:.." lista.new |... (4 Replies)
Discussion started by: kl0x
4 Replies

4. Shell Programming and Scripting

Tricky data manipulation...

Hi everyone.. I am new here, hello.. I hope this doesn't come across to you folks as a stupid question, I'm somewhat new to scripting :) I'm seeking some help in finding a way to manipulate data output for every two characters - example: numbers.lst contains the following output:... (3 Replies)
Discussion started by: explicit
3 Replies

5. Shell Programming and Scripting

Tricky - Need help on Shell script variables

Hi, I have a requirement in which i have to read a csv file and put data in certain set of variables: File content: VP-DTL-REC-CNT, ,854840,0.00,VP-PAID-AMT, ,0,32280885.17,VP-PAT-PAID-AMT, ,0,9930244.32,VP-PAID-REV-CNT, ,484927,0.00,VP-REJ-CNT, ,369913,0.00, , ,0,0.00, , ,0,0.00, , ,0,0.00, ,... (3 Replies)
Discussion started by: shantoshkumar
3 Replies

6. Shell Programming and Scripting

Linux: Writing a tricky script to check connectivity

So, first and foremost, I'm having issues with my internet connection. Periodically, the connection drops across the network. The fix is simple enough: restart the modem. However, this gets old when the connection dies out every hour. I can hit my surfboard on 192.168.100.1, and navigate to a... (5 Replies)
Discussion started by: kungfujoe
5 Replies

7. UNIX for Dummies Questions & Answers

Tricky Quotation Question

Hi, I am at a point in my script where I defined the number of the command line parameter I would like to set a variable equal to: parameter_number=14 I would then like to set a variable equal to the correct parameter: variable=$parameter_number The issue here is that {} is required... (2 Replies)
Discussion started by: msb65
2 Replies

8. Shell Programming and Scripting

Tricky script question

Hi, I'm in the midst of writing a UNIX script that sftp's files to an external host and am stuck with a problem. The problem is that the files created on my server as a order number that correlates to a sequence of directories on the remote host which is where the file should be ftp'ed. ... (3 Replies)
Discussion started by: budrito
3 Replies

9. Shell Programming and Scripting

Tricky Sed

Hello. I am trying to convert occurrences of 'NULL' from a datafile. The 'NULL' occurences appears at this: |NULL| NULL|NULL| NULL|NULL| NULL|NULL| NULL| There should be 52 fields per line. I would like any occurrence of | NULL| or |NULL| to appear as '||' Currently I am using this sed... (2 Replies)
Discussion started by: bestbuyernc
2 Replies

10. Windows & DOS: Issues & Discussions

Tricky one...

Here's my problem: I have a laptop running Windows XP Pro with no internal CD or Floppy drives. I want to install Linux on it. I don't care about the Windows XP Pro installation, in fact I would like to install Linux over the entirety of the HD. However I cannot boot from any external CD drive... (1 Reply)
Discussion started by: saabir
1 Replies
Login or Register to Ask a Question