Fork me on GitHub

Project Notes

#003 the First Line of a File

Notes

I have a text file, but the first line might need modification. What to do?

Reach for perl of course!

This requires a variation of the generic patch_file process described here.

The examples.sh script demonstrates the principle. The example is actually taking a file in Intel Hex format and pre-pending an Extended Linear Address record if one is not already present.

Example

$ ./examples.sh
Installing example.hex from template..

Original example.hex (head only)..
:10000000008000208D030000CD030000CF0300001E
:1000100000000000000000000000000000000000E0
:10002000000000000000000000000000D1030000FC
:100030000000000000000000D3030000D503000012
:10004000D7030000D7030000D7030000D703000048
:10005000D703000000000000D7030000D703000012
:10006000D7030000D7030000D7030000D703000028
:10007000D7030000D7030000D7030000D703000018
:10008000D7030000D7030000D7030000D703000008
:10009000D7030000D7030000D7030000D7030000F8

Step 1: Patching the first line (with file backup)

Cummulative diffs..
1d0
< :020000040000FA

Step 2: Try patching again - should not duplicate (without backup)

Cummulative diffs..
1d0
< :020000040000FA

Resulting example.hex (head only)..
:020000040000FA
:10000000008000208D030000CD030000CF0300001E
:1000100000000000000000000000000000000000E0
:10002000000000000000000000000000D1030000FC
:100030000000000000000000D3030000D503000012
:10004000D7030000D7030000D7030000D703000048
:10005000D703000000000000D7030000D703000012
:10006000D7030000D7030000D7030000D703000028
:10007000D7030000D7030000D7030000D703000018
:10008000D7030000D7030000D7030000D703000008

Credits and References

About LCK#3 perl
Project Source on GitHub Return to the Project Catalog

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

LittleArduinoProjects LittleModelArt More on my blog