sed to have defined positionning on line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to have defined positionning on line
# 8  
Old 04-25-2002
Hi Jimbo,
with your script , I get something like:
# 9  
Old 04-25-2002
Sorry,
I did something wrong.....Smilie

here is what I get:
cin **> comm2.uc ...................................cin **> comm2.uc => Line 208 : (* the user should call Get_Time_LoW, which will load the appropriate *)
cin **> eqom_7.uc ..................................cin **> eqom_7.uc => Line 389 : (* UNUSED ENTRIES - execute appropriate termination *)
cin **> eqom_d.uc ..................................cin **> eqom_d.uc => Line 390 : (* UNUSED ENTRIES - execute appropriate termination *)
cin **> eqom_e.uc ..................................cin **> eqom_e.uc => Line 389 : (* UNUSED ENTRIES - execute appropriate termination *)
cin **> globals.uc .................................cin **> globals.uc => Line 406 : (* - Made changes appropriate to cam edge filtering modifications. *)
cin **> hwi_rm_mios1.c ...........=> Line 138 : ......../* determine which flag generated the int and call the appropriate*/
cin **> hwi_rm_mios1.c ...........=> Line 145 : ..../* - uncomment the appropriate slot */
cin **> hwi_rm_mios1.c ...........=> Line 146 : ..../* - add a call to the appropriate handler */
cin **> hwi_rm_mios1.c ...........=> Line 258 : ......../* determine which flag generated the int and call the appropriate*/
cin **> hwi_rm_mios1.c ...........=> Line 265 : ..../* - uncomment the appropriate slot */
cin **> hwi_rm_mios1.c ...........=> Line 266 : ..../* - add a call to the appropriate handler */
cin **> hwi_spi.c ................=> Line 123 : ....../*-- Enable spi devices by setting appropriate discrete output */
cin **> nitc1.uc ...................................cin **> nitc1.uc => Line 301 : (* UNUSED ENTRIES - execute appropriate termination. *)
cin **> rqom.uc ....................................cin **> rqom.uc => Line 438 : (* UNUSED ENTRIES - execute appropriate termination *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 453 : $ 1 406 (* - Made changes appropriate to cam edge filtering modifications. *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 908 : $ 1 390 (* UNUSED ENTRIES - execute appropriate termination *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 1338 : $ 1 301 (* UNUSED ENTRIES - execute appropriate termination. *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 3020 : $ 1 389 (* UNUSED ENTRIES - execute appropriate termination *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 3480 : $ 1 389 (* UNUSED ENTRIES - execute appropriate termination *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 5712 : $ 1 438 (* UNUSED ENTRIES - execute appropriate termination *)
cin **> scorpio.lst ................................cin **> scorpio.lst => Line 5999 : $ 1 208 (* the user should call Get_Time_LoW, which will load the appropriate *)
cin **> hwi_can.c ................=> Line 327 : ../* Select the appropriate CAN object set */
cin **> hwi_can.c ................=> Line 470 : ../* Select the appropriate CAN object set */
cin **> hwi_can.c ................=> Line 596 : ../* Select the appropriate CAN object set */
cin **> hwi_can.c ................=> Line 795 : ....../* Select the appropriate CAN device */
cin **> hwi_sci.c ................=> Line 540 : ......../* interrupt(s) and then calls the appropriate handling function(s). */
cin **> hwi_sci.c ................=> Line 736 : ......../* bytes as appropriate. */

Any idea ?
homefp
# 10  
Old 04-28-2002
When you first posted some of your actual data ("here is a right copy of my original line", that limited sample showed that the comments were delineated with a traditional syntax for embedded comments: /*..comments.....*/. Now that you have posted more of your data, I can see that I cannot rely on the /* to start your comments.

Without that, it is quite a bit more inconvenient. Start of comments must now be identified as the second word following the word "Line". This involves a little scanning of the line and some checking to ensure that I do not go into an infinite loop. The following code should do it. The only requirements for a data line are:

must contain =>
must contain Line to the right of =>
must have at least two words following Line
must have space-delimited words (not tab-delimited)

There is one rare situation that could cause this to loop, and that is if a data line violated BOTH of the last two rules. I could protect against that with gsub("\t"," ") but your awk does not want to modify $0.

I have the LINE REQUIREMENTS NOT MET just for testing. After testing, you will want to remove that, but you must leave the simple "print" just below it, which is the command that will print the unchanged line.
Code:
#!/bin/sh
awk '{
aloc=index($0,"=>")
cloc=index($0,"Line")+4
for (w=1;w<=NF;w++)
   if ($w=="Line") break
if (aloc==0 || cloc==4 || cloc<aloc || (w+2)>NF)
  {print "LINE REQUIREMENTS NOT MET - FOLLOWING LINE IS UNCHANGED:"
   print}
else
  {while (substr($0,cloc,1)==" ") cloc++
   while (substr($0,cloc,1)!=" ") cloc++
   pad1=substr("....................",1,35-aloc)
   pad1len=length(pad1)
   pad2=substr("....................",1,57-cloc-pad1len)
   print substr($0,1,aloc-1) pad1 \
         substr($0,aloc,cloc-aloc) pad2 \
         substr($0,cloc)}
}' myfile > myNEWfile
exit 0


Last edited by Jimbo; 04-28-2002 at 12:14 PM..
Jimbo
# 11  
Old 04-29-2002
MySQL

Thanks Jimbo for your help.
It seems to work perfectly !
Have a nice day.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

selection particular number of line from a bunch by user defined limits.

hello i am having a file having a matrix as the following 4.1 5.5 6.55 7.2 8.2 1.002 i am having around 1 lakh rows, now i need a program in which i show give min x and min y and min z values and as well as max x max y max z, the values between these minimun and maximum values should be... (1 Reply)
Discussion started by: charan pattabhi
1 Replies

2. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

3. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

4. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

5. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

6. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

7. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

8. Shell Programming and Scripting

Print the 2nd line everytime after defined pattern is found.

Hi, I have a text file similar to the example below and I want to print the second line every time after the "--------------------------" pattern is found. The pattern is a fixed length of - characters. Example of input; 1 -------------------------- 2 3 39184018234 4 ... (10 Replies)
Discussion started by: lewk
10 Replies

9. Shell Programming and Scripting

Sed or Grep to delete line containing patter plus extra line

I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out: Delete every line containing the word CEN and the next line as well. ie. test.txt blue 324 CEN green red blue 324 CEN green red blue to produce:... (2 Replies)
Discussion started by: rocketman88
2 Replies

10. Shell Programming and Scripting

sed/awk to insert comment at defined line number

Hi there, may someone easily help me on this : I want to insert a text in a specific line number like : linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1` line2insert=`expr $linenumb2start + 2` and now I need to replace something like {} with {comment} at... (8 Replies)
Discussion started by: homefp
8 Replies
Login or Register to Ask a Question