Git Product home page Git Product logo

dodo's Introduction

dodo Build Status Coverage Status

dodo - scriptable in place file editor

WARNING

dodo is a work in progress so it is highly recommended you backup any files you are going to modify using dodo.

Description

dodo is a non-interactive scriptable in place file editor.

Purpose

dodo was born from the need to efficiently edit very large files (16GB plain sql dumps), I was unable to do so using my normal toolset (ed, sed or vim) and I realised that writing a tool specifically for this use case would be very simple.

Building

cd dodo
make
make test

Usage

dodo is run and supplied with a single argument representing the filename to work on.

dodo then reads it's commands from stdin, note that dodo is non-interactive so will not start work until it's stdin input is finished (it sees eof).

in dodo all changes are flushed immediately; there are no concepts of 'saving', 'undo' or 'backups'.

dodo is really a very thin wrapper around fread and fwrite.

example dodo usage:

./dodo filename <<EOF
    p          # print 100 bytes
    p5         # print 5 bytes ('hello')
    e/hello/   # expect string 'hello'
    b6         # goto byte 6 in file
    e/world/   # expect string 'world'
    w/marge/   # write string 'marge' (writes over 'world')
    b38        # goto byte 38 in file
    e/sl\/ash/ # expect string 'sl/ash'
    w/slashy/  # write over string 'sl/ash' with 'slashy'
    q          # quit
EOF

each of the commands is explained below in more detail.

Commands

dodo currently supports the following commands and syntax:

print

p
pnumber

print specified number of bytes, if number is not specified will default to 100

line:

lnumber

place cursor at the start of 'number'-th line. Warning: this may be expensive in large files

expect:

e/string/

check for 'string' at current cursor position, exit with error if not found.

expect does not move the cursor.

byte:

bnumber

move cursor to absolute byte 'number' within file

write:

w/string/

write 'string' to current cursor position, this will overwrite any characters in the way

write moves the cursor by the number of bytes written

truncate:

truncate the file at the current cursor position. Note that since the cursor can be inside or outside of the file, this can be used to truncate or extend files.

quit:

q

exit dodo, quit is not actually needed as EOF will trigger an implicit quit.

Syntax

comments: dodo also supports comments

# this is a comment and spans until \n

whitespace:

in dodo whitespace is non-significant except in the case of a newline ('\n') terminating a comment

escape character: a backslash can be used as an escape character, useful mainly when the expected string or replacement string has to include a string delimiter (forward slash)

e/foo\/bar/
w/baz\\qux/

will replace foo/bar with baz\qux

Contributions

Chris Hall

David Phillips

Tom Ryder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.