Replacing line number w/spaces in DSDT compiler log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing line number w/spaces in DSDT compiler log
# 1  
Old 08-11-2010
Replacing line number w/spaces in DSDT compiler log

Hi, all,
I'm from the 8-bit micro days (Z-80, 6809, 6502, etc.) and used to program in assembly and machine code. But, that was 25 years ago and life happened. Now, I'm scripting for the hackintosh community and love every bit of it.

I'm parsing a DSDT compiler log for error/warning/remarks checking and would like to be able to replace the line number with spaces, because I need to retain the spacing. The positioning of the text is critical, as it points to the errors, as you'll see in the following example. The line number follows the dsdt_fixed.txt path. See the following random examples:

Code:
Debug/dsdt_fixed.txt   140:         Name (_T_0, Zero)
Remark   5111 -                              ^ Use of compiler reserved name (_T_0)

Debug/dsdt_fixed.txt 10965:             Acquire (MUTE, 0x03E8)
Warning  1105 -        Possible operator timeout is ignored ^ 

Debug/dsdt_fixed.txt 12151:             Store (FGET (Local0), Local1)
Warning  1093 -                                   ^ Called method may not always return a value

I'm removing the line number so I can do comparisons after DSDT editing. The editing may add/remove lines, so the line number will be pointing to different locations. I have all this figured out, but just think there's got to be a simpler way to accomplish this task.

A simple sed 's/[0-9]/ /g' won't work, as I may have digits in the rest of the line. Is there a way to limit the search/replace to just that line number or area of text, ignoring the rest of the DSDT code that follows on that line?

Here's the details:
"Debug/dsdt_fixed.txt" is a predictable string.
Line number appears to be in a fixed, flush right location, with padded spaces at left. (The compiler may determine the maximum number of lines in the code and set the number of spaces in advance.)

I was doing this in bash by breaking up the line, which works fairly well, but was relatively slow.
Code:
parse_dsdt_log(){
CM_LST=""
# Grep "Warning" and previous line; add "@" at beginning of line; strip newlines
# Replace "@" with newline; remove "--" divider added by grep -B1 command
CM_LST2=`echo "$TEMP" | grep -B1 "^${PARSE}" | sed 's/^'"$DSDT_PATH"'/@&/g' | tr -d '\n' | tr '@' '\n' | sed 's/--$//g'`

while read LINE; do

# Extract file path and line number
	NUM=`echo "$LINE" | sed 's/\('"$DSDT_PATH"' [0-9]*:\).*$/\1/'`

# Calculate number of characters in number and replace with spaces
	SPC=$( printf "%${#NUM}s" )
	SPC="${SPC// / }"
	LINE=`echo "$LINE" | sed 's/'"$DSDT_PATH"' [0-9]*: \(.*$\)/'"$SPC"' \1/'`

# Merge back lines
	CM_LST="$CM_LST
$LINE"

done<<<"$CM_LST2"
}

PARSE="Warning"
DSDT_PATH="Debug.*"
parse_dsdt_log

Then, I thought of this idea. It works fast fine, but seems amateurish:
Code:
PARSE="Warning"
PTH="Debug\/dsdt_fixed.txt "

CM_LST=`echo "$TEMP" | grep -B1 "^${PARSE}" | sed 's/^\('"$PTH"'\).:/\1  /;s/^\('"$PTH"'\)..:/\1   /'`
CM_LST=`echo "$CM_LST" | sed 's/^\('"$PTH"'\)...:/\1    /;s/^\('"$PTH"'\)....:/\1     /;s/^\('"$PTH"'\).....:/\1      /'`

EDIT: Okay, I need to change the order of the commands so that sed replaces the largest number first and works on down. Whoops.
Code:
PARSE="Warning"
PTH="Debug\/dsdt_fixed.txt "

CM_LST=`echo "$TEMP" | grep -B1 "^${PARSE}" | sed 's/^\('"$PTH"'\)[0-9][0-9][0-9][0-9][0-9]:/\1      /;s/^\('"$PTH"'\) [0-9][0-9][0-9][0-9]:/\1      /'`
CM_LST=`echo "$CM_LST" | sed 's/^\('"$PTH"'\)  [0-9][0-9][0-9]:/\1      /;s/^\('"$PTH"'\)   [0-9][0-9]:/\1      /;s/^\('"$PTH"'\)    [0-9]:/\1      /'`

THIRD EDIT <sigh>: Okay, I had to add the padding in front of the numbering, as well as the [0-9] regex, instead of "." Works correctly, now.
Surely, there's a better idea, right? Nothing wrong with it, except it just seems verbose. However, I'm sticking with the code, until I get a better solution. Smilie

best of wishes,
MAJ

---------- Post updated at 07:02 PM ---------- Previous update was at 06:04 PM ----------

While I'm still talking to myself Smilie, it seems the extended regex works, too.

Code:
PARSE="Warning"
PTH="Debug\/dsdt_fixed.txt "

CM_LST=`echo "$TEMP" | sed 's/^\('"$PTH"'\)[0-9]\{5\}:/\1      /;s/^\('"$PTH"'\) [0-9]\{4\}:/\1      /'`
CM_LST=`echo "$CM_LST" | sed 's/^\('"$PTH"'\)  [0-9]\{3\}:/\1      /;s/^\('"$PTH"'\)   [0-9]\{2\}:/\1      /;s/^\('"$PTH"'\)    [0-9]:/\1      /'`

Thanks for letting me think out loud. I was working on this off and on for the past two days. Nothing like stalling on something seemingly "simple." Going to bed, then thinking, "Oh, I got it!" Get up and find out, nope, that doesn't work. Go back to bed. Rinse, lather, repeat.

MAJ

EDIT: Sorry to litter this place up. But, I think was making things a bit more complicated that necessary. Once I determine the number of spaces set by the compiler, it's a simple line of code:

Code:
PARSE="Warning"
PTH="Debug\/dsdt_fixed.txt "

CM_LST=`echo "$CM_LST2" | sed 's/^\('"$PTH"'\)....../\1      /'`


Last edited by digital_dreamer; 08-11-2010 at 09:18 PM.. Reason: More edits, refreshed thinking about issue!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

2. Shell Programming and Scripting

Replacing certain positions in lines with spaces

Hello, I have a file with hundreds of lines. Now I need to replace positions 750-766 in each line (whatever there is there) with spaces... how can I do that? Which command to use? The result will be all the lines in the file will have spaces in positions 750-766. Thanks! (3 Replies)
Discussion started by: netrom
3 Replies

3. Shell Programming and Scripting

Replacing white spaces in filename

Hi; In following code find LOG_DIR -type f | while read filename; do echo $filename; done I want to precede each white space encountered in filename with \ so that when i use $filename for running some commands in do...done,it wont give me an error. will appreciate ur help in this.... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

4. Shell Programming and Scripting

Replacing tabs with spaces

I want my program to replace tabs with spaces.1tab=4spaces.When i write aa(tab)aaa(tab)(tab)a(tab) it must show me aaxxaaaxxxxxaxxx. I think that my program works corectly but when a write aaa(tab)a it must show aaaxa but it is aaaxxxxxa.Please for help!!! That is my code: #include <stdio.h> ... (3 Replies)
Discussion started by: marto1914
3 Replies

5. Shell Programming and Scripting

Replacing the new character with spaces

Hi Experts, We are facing some while loading the "csv" file to target table.Some of the records are having values as : Account number,Name,Address "123","XYZ","302 Street,Washington,US" "456","PQR"," 3233 Some Street, Washington,US" In the above file instead reading only two records it... (11 Replies)
Discussion started by: Amey Joshi
11 Replies

6. Shell Programming and Scripting

trim spaces and replacing value

Hi, I have a file origFile.txt with values: origFile.txt .00~ 145416.02~ xyz~ ram kishor ~? ~ ~783.9 .35~ 765.76~ anh reid~ kelly woodburg ~nancy ~ ~? Now each row in the file has value for 7 columns with "~" as delimiter. The requirement was i)I need to erase the blank spaces between... (2 Replies)
Discussion started by: badrimohanty
2 Replies

7. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

8. UNIX for Dummies Questions & Answers

Replacing the Spaces

Hi, i have a tab dilimeted file.The records are :header is having column names.I am facing the following issue : I want to convert the spaces only for header file into "_" in the unix shell but the problem is that if i use sed command all the blank spaces are getting replaced by "_". For... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

9. Shell Programming and Scripting

need help in replacing spaces in a file

hi all this is the part i am facing a problem eg data: filename : tr1 + T 40 this is a sample record in that file ... the value of T can be anything, but will be a single character. i need to cut from field two, and i am using this command cut -d " " -f2 tr1 >tr3 and the o/p is ... (7 Replies)
Discussion started by: sais
7 Replies

10. Shell Programming and Scripting

replacing tabs to spaces from files

hi, I have some 50 C files in which for indentation of code some devlopers used tabs, but we dont want any tab used for indentation. I have following 2 need. 1) find tabs from all 50 files (which are in one directory ) 2) replace them with 4 spaces. Thanks Rishi (6 Replies)
Discussion started by: rishir
6 Replies
Login or Register to Ask a Question