source: ccr2ccd-xslt/trunk/make/LineNumberUpDownFunction@ 1523

Last change on this file since 1523 was 1033, checked in by mishpers@gmail.com, 14 years ago

Add missing files that were on Nancy's local computer

File size: 4.3 KB
Line 
1#!/bin/bash
2
3
4#Recomment that all arguments that are not stright forward be enclosed in single quotes
5#Example call is
6#$ source KeyUpDownFunction
7#$ KeyUpDownFunction 'root="PROCEDURE_4234_52' '<entry ' '</entry>' 'MyTestFile.xml'
8
9#First argument is the line number inside the section you wish to isolate. for instance for a problem, it might be a number you have collected from a file containing all of the line numbers of the problem QRDA template, 2.16.840.1.113883.3.249.11.100.8
10#Second argument is the tag or some other marker of the top of the section you with to isolate such as <component> or prehaps <entry>
11#Third argument is the tag or some other marker of the top of the section you with to isolate such as </component> or prehaps </entry>
12#fourth argument is the filename you are doing this in
13#The fifth argument is optional and is the Marker you wish to leave in the file showing where this section began. It might be an empty tag or a comment - this part has not been added to the function yet
14LineNumberUpDownFunction()
15{
16 local LineNum
17 local Result
18 local BeginLineNum
19 local EndLineNum
20 local Result2
21 local KeyLineNumber
22 local Marker
23
24 File="$4"
25 echo "File is $File"
26 KeyLineNumber="$1"
27 echo "KeyLineNumber is $KeyLineNumber"
28 StartElement="$2"
29 echo "Starting Element is $StartElement"
30 EndElement="$3"
31 echo "EndElement is $EndElement"
32 #Marker="$5"
33 LineNum="$KeyLineNumber"
34 echo "LineNum is starting at $KeyLineNumber"
35 #Start at the line number you have chosen and move
36 #backward one line at a time and find the line number of that has what is in the second argument
37 #Greping for the Element LineNumb returns $? with 0 is true and 1 is false if the element is in the line
38 #work backwards from LineNum to find the line with what you want in it
39 Result="$(head -"$LineNum" "$File" |tail -1 | grep -q "$StartElement";echo $?)"
40 echo "Result of last check of the line number is $Result"
41 echo "The current line number being tested is $LineNum"
42 echo "The next line number to test is $(($LineNum-1))"
43 while [ "1" = "$Result" ]
44 do
45 LineNum="$(($LineNum-1))"
46 echo "$LineNum"
47 Result="$(head -"$LineNum" "$File" |tail -1 | grep -q "$StartElement";echo $?)"
48 done
49 BeginLineNum="$LineNum"; echo "BeginLineNum is $BeginLineNum"
50 #initialize EndLineNum which will ultimately be the line with the ending component tag, "$EndElement"
51 EndLineNum="$(($LineNum+1))"; echo "EndLineNum is starting at $EndLineNum"
52 #This is to check the line and if it does not contain $EndElement, add 1 to EndLineNum and go to the next line and check that one
53 Result2="$(head -"$EndLineNum" "$File" | tail -1| grep -q "$EndElement";echo "$?")"
54 #Result2="$(sed -n "$EndLineNum"p "$File" | grep -q "$EndElement";echo "$?")"
55 echo "Result2 is $Result2"
56 while [ "$Result2" = "1" ]
57 do
58 EndLineNum="$(($EndLineNum+1))"
59 echo "EndLineNum is $EndLineNum"
60 # echo "$(head -"$EndLineNum" "$File" | tail -1)"
61 Result2="$(head -"$EndLineNum" "$File" | tail -1 | grep -q "$EndElement";echo "$?")"
62 echo "Result2 is $Result2 and the EndElement is $EndElement and current line being teste is $EndLineNum"
63 done
64 echo "Beginning line Number of the Section is $BeginLineNum"
65 echo "Ending Line Number of the Section is $EndLineNum"
66
67 #Now you know the beginning and ending line number of the section so you can delete it or process it somehow. It returns the key and name beginning line number the ending line number, the marker and the file
68 echo " KeyLineNumber is $KeyLineNumber, the Beginning of the section has the starting element $StartElement and is on line number $BeginLineNum and the line number that EndElement which is $EndElement is $EndLineNum, the File name is $File and the place holder left in the file, if there is one, is $Marker"
69 #The Test Section information variable is available to use in your additional processing
70 SectionInformation="$(echo "$KeyLineNumber:$BeginLineNum:$EndLineNum:$File $Marker")"
71 echo "end LineNumberUpDownFunction"
72 echo "the KeyLineNumer BeginlineNum and EndLineNum File and Marker have been written to the variable SectionInformation separated by colons."
73 echo "$KeyLineNumber:$BeginLineNum:$EndLineNum:$File $Marker"
74 #echo "Do you wish to delete the Marker?"
75 read
76
77}
Note: See TracBrowser for help on using the repository browser.