Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a file with a script

Status
Not open for further replies.

domenicodl

Programmer
Jul 2, 2011
15
IT
hello,
I wrote a very elementary awk script that takes two files in input. One of the two files is used to select the rows of the other one.
The file pctrace is used to extract the line from the file disassembly.
Here's a snapshot of both:
pctrace
"2000"
"2004"

disassembly
00002000 3D 20 00 40 lis r9,400000
00002004 39 29 A0 00 addi r9,-6000
00002008 80 09 00 00 lwz r0,00(r9)

I remove the first four zero in the first field of disassembly and then I compare. For this example with the file pctrace I can select only the first two lines.
Now the problem is that my script works fine when I use it with a "handmade" pctrace (I wrote it with nano), but it doesn't work when I use the file pctrace.csv (that I get from a database).
Those two files are identical to me.
I have attached all the files needed to execute the program, can someone take a look at it them, please?
The script is about 10 lines code (qute stupid).
To invoke the script I use the command awk -f pctrace disassembly
for the second file obviously awk -f pctrace.csv disassembly
Thank you in advance
 
Hi

I suppose you already found the solution based on the conclusion in thread271-1655156.

So just a few notes to avoid such unpleasant situations in the future :
[ul]
[li]some editors, like Midnight Commander's built-in editor always display the [tt]\r[/tt] characters as [tt]^M[/tt][/li]
[li]in other editors, like Vim this behavior is configurable[/li]
[li]the [tt]od[/tt] tool with [tt]-a[/tt] option will display the characters and the abbreviation of their names, marking [tt]\r[/tt] as "cr"[/li]
[li]the dos2unix tool removes the trailing [tt]\r[/tt] characters from a file[/li]
[li]the same does the [tt]sed -i 's/\r$//' /input/file[/tt] command too[/li]
[/ul]


Feherke.
 
Thank you for this final remark, very interesting.
Anyway I will be checking how to display the carriage return with nano.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top