SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
Tools for effective data/file manipulation
   and greater research productivity
              (and happiness)

                Wes Huang
         Algorithmic Robotics Lab
      Department of Computer Science
      Rensselaer Polytechnic Institute
            November 17, 2004




                     1
Learn to use your tools well!

• Many data/file manipulation tasks:
  – reformat a data file
  – scan files for information
  – rename batches of files
  – etc.
• Don’t do it manually!
• Don’t write a C++ program!
• Some tools at your disposal:
  – GNU Emacs
  – BASH shell (& scripts)
  – Ruby




                          2
GNU Emacs

• Extremely powerful editor
• Learn the basic key bindings! A few examples:
  – C-v, M-v ≡ scroll up/down page
    I see too many students who press the up arrow
    and wait!
  – C-s, C-r ≡ isearch forward/backward
• Learn key bindings beyond the basics! For example:
  – M-a, M-e ≡ backward/forward sentence
    You need to have 2 spaces after sentence ending
    punctuation for this to work.
  – M-{, M-} ≡ backwards/forwards paragraph
  – C-M-b, C-M-f ≡ backwards/forwards
    s-expression (balanced expression)
  – C-u ≡ ×4 multiplier. Examples:
    ∗ C-u M-f forward 4 words
    ∗ C-u C-u C-p up 16 lines
    ∗ C-u C-u C-u ; 64 semicolons
  – M-% ≡ query replace. Type original text,
    replacement text, and then:
    ∗ space to replace
    ∗ ‘n’ to not replace
    ∗ ‘!’ to replace the rest (no more questions)
    ∗ there are other commands...
                         3
GNU Emacs keyboard macros

• record a sequence of keystrokes/commands and
  then repeatedly execute them.
• C-x ( ≡ starts recording macro
  C-x ) ≡ stops recording macro
• When you define the macro, you will do the
  operation on the first instance.
• Try out the macro a few times to make sure it’s
  doing the right thing. (Then run it lots of times.)
  Know the undo command: C-/ or C-_
• If the “bell rings” (i.e., you get an error beep), then
  you have to start over. (Will also terminate the
  macro during execution.) Most commonly because
  you search for a string that isn’t found.
• To execute macro: C-x C-e
  Use prefix commands to execute multiple times:
  C-u C-x C-e ≡ 4 times
  C-u C-2 C-7 C-x C-e ≡ 27 times




                            4
GNU Emacs keyboard macro tips

• You need to be strategic about the sequence of
  commands!
• Create a line/record/instance oriented macro:
  – Start cursor at beginning of line/record/instance
  – Do the operation
  – Move the cursor to the beginning of the next
    line/record/instance
• Helpful commands:
  – C-a to put cursor at beginning of line
  – C-} to move to the beginning of the next
    paragraph (useful when records are separated by
    blank lines)
  – C-s to search forward to the next instance
• Be careful about variations in your data, for
  example:
  – tabs versus spaces
  – multi-word last names
  – variations in spacing




                           5
GNU Emacs keyboard macro examples

• Insert a “> ” at beginning of each line. (I know
  there’s probably a better way to do this, but I
  actually use this macro a lot.)
   C-x ( start macro (assume cursor at beginning of line)
   >        type characters
   C-a      beginning of line
   C-n      next line
   C-x ) end macro
• Change: epsfig{file=pic.eps}
       to: includegraphics{pic}
  C-x (             start macro
  C-s epsfig       search for “epsfig”
  RET               stop search
  M-BKSP            backward delete word (“epsfig”)
  includegraphics type text
  C-s file=         search for “file=”
  RET               stop search
  M-BKSP            backward delete word (“file=”)
  C-s .eps          search for “.eps”
  RET               stop search
  M_BKSP            backward delete word (“eps”)
  BKSP              delete character (“.”)
  C-x )             end macro
                         6
GNU Emacs Major Modes

• Many different modes for different types of files and
  operations:
  – Fundamental
  – Text
  – LaTeX
  – HTML
  – C, C++
  – DirEd
  – and many more. . .
• Major modes have specialized key bindings
• For example, in LTEX mode:
                  A

  – C-c C-f ≡ run L TEX on buffer
                      A

  – C-c C-o ≡ open L TEX block
                        A

    ∗ asks what kind of block you want (with
      autocompletion when you hit tab/space)
    ∗ inserts begin{...} and end{...}
    ∗ doesn’t work for “document” for some reason
  – C-c C-e ≡ end L TEX block
                       A

    closes the closest open begin{...} block
  – M-RET ≡ insert item

                          7
BASH shell

• Useful for file manipulation and applying UNIX
  commands
• You can write BASH shell scripts, but. . .
• You can do a lot from the command line!
• One of the most useful commands:
  for var in ... do ... done
• For example:
 for d in */*.scm; do
   mv $d scheme_progs/
 done
 You can enter this on the command line!
• The “word list” given (after “in”) need not be file
  names. For example:
 for d in 3 2 1; do let x=$d+1;
   mv file$d.txt file$x.txt; done
 Renames file3.txt to file4.txt, file2.txt
 to file3.txt, etc.
 Need to use a let statement to make an integer
 variable.


                           8
BASH shell variables

• Often you only want part of a string variable:
  ${d#*/}     remove everything from start to the first /
  ${d##*/}    remove everything from start to the last /
  ${d%.*}     remove everything from last . to the end
  ${d%%.*}    remove everything from first . to the end
• For example:
  for d in *.[1-9]*.scm; do
    mv $d ${d%%.*-${d#*.}
  done
  Renames files of the form whuang.1.scm to
  whuang-1.scm




                          9
Ruby

• My new favorite scripting language!
• BASH is good for file manipulation and using UNIX
  commands to process files. It is not well suited to
  directly process information in the file! Ruby is well
  suited for this.
• Ruby (so I am told) is like a combination of:
  – Smalltalk (a very object oriented language)
  – Perl (powerful “write-only” scripting language)
• If you already know perl, maybe you don’t want to
  learn ruby.
  If you don’t know perl, learn Ruby instead!
• Easy file processing
• Provides extensive libraries for:
  – Arrays
  – Strings
  – Hash tables
  – http
  – date/time
  – much, much more. . .


                           10
Ruby example

Select and rearrange fields in a comma/tab separated
spreadsheet file
# These are the fields I want in the proper order
outfields = ["Name", "Quiz1", "Quiz2", "Assign1", "Assign2"]

# read first line of file (which has column headings)
headingstr = gets

# split the string to create an array of the column headings
headings = headingstr.split(/,|t/)

# read each line of the file
while instr = gets
  # split it on commas/tabs to get each field
  data = instr.split(/,|t/)

  # create an array of the selected fields in output order
  # this uses a "closure" --- like a lambda fn
  # for each field, it looks up its index in the headings array
  # and selects that fields in the current data
  rearr = outfields.each { |f| data[headings.index(f)] }

  # turn this array of strings into a single string
  # with a comma separating each field
  outstr = rarr.join(",")

  puts outstr
end




                            11
References

• GNU Emacs
  – The O’Reilly book is good; it goes beyond the
    basics but doesn’t get too advanced.
  – Emacs info mode contains documentation of most
    everything. Type: C-h i
  – There is also plenty of stuff online.
• BASH
  – Again, I like the O’Reilly book — I keep it right at
    my desk. Nice presentation. Covers a lot of stuff.
  – The UNIX man page has pretty much everything
    you want to know, albeit in a somewhat less
    accessible format.
  – Plenty of stuff online too. . .
• Ruby
  – The book “Programming Ruby” by Thomas and
    Hunt is, I think, the standard tutorial/reference
    book.
  – The first edition of this book is mostly online:
    http://www.rubycentral.com/book/index.htm
    Note: the online chapters are not complete, but
    it’s still quite useful.
  – There is now (as of Oct 2004) a 2nd edition
    available.
                          12
Other resources

• You can look at some of my initialization files (in
  /cs/whuang):
  – .emacs
    Emacs initialization file loaded every time emacs
    starts.
  – .bashrc
    BASH initialization file loaded every time a new
    shell starts.
    My convention is to keep system-specific things
    in my .bashrc such as environment variable
    definitions.
  – .alias
    I source this file from my .bashrc. It contains
    stuff such as aliases and functions that I want on
    all my systems (e.g., SunOS at RPI, linux at home,
    and for cygwin (and linux) on my laptop)




                          13

Weitere ähnliche Inhalte

Was ist angesagt?

Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
Unix And C
Unix And CUnix And C
Unix And CDr.Ravi
 
15 practical grep command examples in linux
15 practical grep command examples in linux15 practical grep command examples in linux
15 practical grep command examples in linuxTeja Bheemanapally
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing toolsroot_fibo
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4Prerna Sharma
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Stringsphanleson
 
15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unix15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unixchinkshady
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts Pavan Babu .G
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1tutorialsruby
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer OverflowsSumit Kumar
 
08 text processing_tools
08 text processing_tools08 text processing_tools
08 text processing_toolsShay Cohen
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyOlivier Bourgeois
 

Was ist angesagt? (18)

Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Unix Tutorial
Unix TutorialUnix Tutorial
Unix Tutorial
 
Linux intro 3 grep + Unix piping
Linux intro 3 grep + Unix pipingLinux intro 3 grep + Unix piping
Linux intro 3 grep + Unix piping
 
Unix And C
Unix And CUnix And C
Unix And C
 
15 practical grep command examples in linux
15 practical grep command examples in linux15 practical grep command examples in linux
15 practical grep command examples in linux
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing tools
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
 
2.Format Strings
2.Format Strings2.Format Strings
2.Format Strings
 
15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unix15 practical grep command examples in linux : unix
15 practical grep command examples in linux : unix
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Buffer overflow null
Buffer overflow nullBuffer overflow null
Buffer overflow null
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
Buffer Overflows
Buffer OverflowsBuffer Overflows
Buffer Overflows
 
08 text processing_tools
08 text processing_tools08 text processing_tools
08 text processing_tools
 
Unix
UnixUnix
Unix
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
 

Andere mochten auch

Case Solution for eHarvest.com
Case Solution for eHarvest.comCase Solution for eHarvest.com
Case Solution for eHarvest.comcasesolutions12
 
Lucene 全文检索实践
Lucene 全文检索实践Lucene 全文检索实践
Lucene 全文检索实践yiditushe
 
Echinoderms
EchinodermsEchinoderms
EchinodermsTamara
 
Sponges
SpongesSponges
SpongesTamara
 
Case Solution for Empire Company Limited: The Oshawa Group Limited Proposal
Case Solution for Empire Company Limited: The Oshawa Group Limited ProposalCase Solution for Empire Company Limited: The Oshawa Group Limited Proposal
Case Solution for Empire Company Limited: The Oshawa Group Limited Proposalcasesolutions12
 
resume_eric_tachibana
resume_eric_tachibanaresume_eric_tachibana
resume_eric_tachibanatutorialsruby
 
A CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTE
A CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTEA CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTE
A CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTEProfessorPrincipiante
 
New Zeeland 22 0 Lecointe
New Zeeland 22 0 LecointeNew Zeeland 22 0 Lecointe
New Zeeland 22 0 LecointeMireia Buchaca
 
快速提高你的Sql运行速度
快速提高你的Sql运行速度快速提高你的Sql运行速度
快速提高你的Sql运行速度yiditushe
 
Mimos Esto Tambien Es Arte
Mimos   Esto Tambien Es ArteMimos   Esto Tambien Es Arte
Mimos Esto Tambien Es ArteMireia Buchaca
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...tutorialsruby
 

Andere mochten auch (17)

Case Solution for eHarvest.com
Case Solution for eHarvest.comCase Solution for eHarvest.com
Case Solution for eHarvest.com
 
Up Up And Away
Up Up And AwayUp Up And Away
Up Up And Away
 
Lucene 全文检索实践
Lucene 全文检索实践Lucene 全文检索实践
Lucene 全文检索实践
 
Aanbeveling
AanbevelingAanbeveling
Aanbeveling
 
Echinoderms
EchinodermsEchinoderms
Echinoderms
 
Sponges
SpongesSponges
Sponges
 
Rothke Talk
Rothke TalkRothke Talk
Rothke Talk
 
Case Solution for Empire Company Limited: The Oshawa Group Limited Proposal
Case Solution for Empire Company Limited: The Oshawa Group Limited ProposalCase Solution for Empire Company Limited: The Oshawa Group Limited Proposal
Case Solution for Empire Company Limited: The Oshawa Group Limited Proposal
 
chemist
chemistchemist
chemist
 
resume_eric_tachibana
resume_eric_tachibanaresume_eric_tachibana
resume_eric_tachibana
 
A CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTE
A CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTEA CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTE
A CONTRIBUIÇÃO DO PIBID NA FORMAÇÃO DOCENTE INICIANTE
 
New Zeeland 22 0 Lecointe
New Zeeland 22 0 LecointeNew Zeeland 22 0 Lecointe
New Zeeland 22 0 Lecointe
 
Begin Design
Begin DesignBegin Design
Begin Design
 
快速提高你的Sql运行速度
快速提高你的Sql运行速度快速提高你的Sql运行速度
快速提高你的Sql运行速度
 
Mimos Esto Tambien Es Arte
Mimos   Esto Tambien Es ArteMimos   Esto Tambien Es Arte
Mimos Esto Tambien Es Arte
 
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
exploit-writing-tutorial-part-5-how-debugger-modules-plugins-can-speed-up-bas...
 
hailpern-interact09
hailpern-interact09hailpern-interact09
hailpern-interact09
 

Ähnlich wie tools

Ähnlich wie tools (20)

Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Emacs tutorial
Emacs tutorialEmacs tutorial
Emacs tutorial
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Bioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekingeBioinformatics p4-io v2013-wim_vancriekinge
Bioinformatics p4-io v2013-wim_vancriekinge
 
DevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung FooDevChatt 2010 - *nix Cmd Line Kung Foo
DevChatt 2010 - *nix Cmd Line Kung Foo
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Linuxppt
LinuxpptLinuxppt
Linuxppt
 
Slides
SlidesSlides
Slides
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Bash production guide
Bash production guideBash production guide
Bash production guide
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Bozorgmeh os lab
Bozorgmeh os labBozorgmeh os lab
Bozorgmeh os lab
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
Basic Linux Commands
Basic Linux CommandsBasic Linux Commands
Basic Linux Commands
 
Love Your Command Line
Love Your Command LineLove Your Command Line
Love Your Command Line
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.ppt
 
Nithi
NithiNithi
Nithi
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 

Mehr von tutorialsruby

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Mehr von tutorialsruby (20)

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Kürzlich hochgeladen

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Kürzlich hochgeladen (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

tools

  • 1. Tools for effective data/file manipulation and greater research productivity (and happiness) Wes Huang Algorithmic Robotics Lab Department of Computer Science Rensselaer Polytechnic Institute November 17, 2004 1
  • 2. Learn to use your tools well! • Many data/file manipulation tasks: – reformat a data file – scan files for information – rename batches of files – etc. • Don’t do it manually! • Don’t write a C++ program! • Some tools at your disposal: – GNU Emacs – BASH shell (& scripts) – Ruby 2
  • 3. GNU Emacs • Extremely powerful editor • Learn the basic key bindings! A few examples: – C-v, M-v ≡ scroll up/down page I see too many students who press the up arrow and wait! – C-s, C-r ≡ isearch forward/backward • Learn key bindings beyond the basics! For example: – M-a, M-e ≡ backward/forward sentence You need to have 2 spaces after sentence ending punctuation for this to work. – M-{, M-} ≡ backwards/forwards paragraph – C-M-b, C-M-f ≡ backwards/forwards s-expression (balanced expression) – C-u ≡ ×4 multiplier. Examples: ∗ C-u M-f forward 4 words ∗ C-u C-u C-p up 16 lines ∗ C-u C-u C-u ; 64 semicolons – M-% ≡ query replace. Type original text, replacement text, and then: ∗ space to replace ∗ ‘n’ to not replace ∗ ‘!’ to replace the rest (no more questions) ∗ there are other commands... 3
  • 4. GNU Emacs keyboard macros • record a sequence of keystrokes/commands and then repeatedly execute them. • C-x ( ≡ starts recording macro C-x ) ≡ stops recording macro • When you define the macro, you will do the operation on the first instance. • Try out the macro a few times to make sure it’s doing the right thing. (Then run it lots of times.) Know the undo command: C-/ or C-_ • If the “bell rings” (i.e., you get an error beep), then you have to start over. (Will also terminate the macro during execution.) Most commonly because you search for a string that isn’t found. • To execute macro: C-x C-e Use prefix commands to execute multiple times: C-u C-x C-e ≡ 4 times C-u C-2 C-7 C-x C-e ≡ 27 times 4
  • 5. GNU Emacs keyboard macro tips • You need to be strategic about the sequence of commands! • Create a line/record/instance oriented macro: – Start cursor at beginning of line/record/instance – Do the operation – Move the cursor to the beginning of the next line/record/instance • Helpful commands: – C-a to put cursor at beginning of line – C-} to move to the beginning of the next paragraph (useful when records are separated by blank lines) – C-s to search forward to the next instance • Be careful about variations in your data, for example: – tabs versus spaces – multi-word last names – variations in spacing 5
  • 6. GNU Emacs keyboard macro examples • Insert a “> ” at beginning of each line. (I know there’s probably a better way to do this, but I actually use this macro a lot.) C-x ( start macro (assume cursor at beginning of line) > type characters C-a beginning of line C-n next line C-x ) end macro • Change: epsfig{file=pic.eps} to: includegraphics{pic} C-x ( start macro C-s epsfig search for “epsfig” RET stop search M-BKSP backward delete word (“epsfig”) includegraphics type text C-s file= search for “file=” RET stop search M-BKSP backward delete word (“file=”) C-s .eps search for “.eps” RET stop search M_BKSP backward delete word (“eps”) BKSP delete character (“.”) C-x ) end macro 6
  • 7. GNU Emacs Major Modes • Many different modes for different types of files and operations: – Fundamental – Text – LaTeX – HTML – C, C++ – DirEd – and many more. . . • Major modes have specialized key bindings • For example, in LTEX mode: A – C-c C-f ≡ run L TEX on buffer A – C-c C-o ≡ open L TEX block A ∗ asks what kind of block you want (with autocompletion when you hit tab/space) ∗ inserts begin{...} and end{...} ∗ doesn’t work for “document” for some reason – C-c C-e ≡ end L TEX block A closes the closest open begin{...} block – M-RET ≡ insert item 7
  • 8. BASH shell • Useful for file manipulation and applying UNIX commands • You can write BASH shell scripts, but. . . • You can do a lot from the command line! • One of the most useful commands: for var in ... do ... done • For example: for d in */*.scm; do mv $d scheme_progs/ done You can enter this on the command line! • The “word list” given (after “in”) need not be file names. For example: for d in 3 2 1; do let x=$d+1; mv file$d.txt file$x.txt; done Renames file3.txt to file4.txt, file2.txt to file3.txt, etc. Need to use a let statement to make an integer variable. 8
  • 9. BASH shell variables • Often you only want part of a string variable: ${d#*/} remove everything from start to the first / ${d##*/} remove everything from start to the last / ${d%.*} remove everything from last . to the end ${d%%.*} remove everything from first . to the end • For example: for d in *.[1-9]*.scm; do mv $d ${d%%.*-${d#*.} done Renames files of the form whuang.1.scm to whuang-1.scm 9
  • 10. Ruby • My new favorite scripting language! • BASH is good for file manipulation and using UNIX commands to process files. It is not well suited to directly process information in the file! Ruby is well suited for this. • Ruby (so I am told) is like a combination of: – Smalltalk (a very object oriented language) – Perl (powerful “write-only” scripting language) • If you already know perl, maybe you don’t want to learn ruby. If you don’t know perl, learn Ruby instead! • Easy file processing • Provides extensive libraries for: – Arrays – Strings – Hash tables – http – date/time – much, much more. . . 10
  • 11. Ruby example Select and rearrange fields in a comma/tab separated spreadsheet file # These are the fields I want in the proper order outfields = ["Name", "Quiz1", "Quiz2", "Assign1", "Assign2"] # read first line of file (which has column headings) headingstr = gets # split the string to create an array of the column headings headings = headingstr.split(/,|t/) # read each line of the file while instr = gets # split it on commas/tabs to get each field data = instr.split(/,|t/) # create an array of the selected fields in output order # this uses a "closure" --- like a lambda fn # for each field, it looks up its index in the headings array # and selects that fields in the current data rearr = outfields.each { |f| data[headings.index(f)] } # turn this array of strings into a single string # with a comma separating each field outstr = rarr.join(",") puts outstr end 11
  • 12. References • GNU Emacs – The O’Reilly book is good; it goes beyond the basics but doesn’t get too advanced. – Emacs info mode contains documentation of most everything. Type: C-h i – There is also plenty of stuff online. • BASH – Again, I like the O’Reilly book — I keep it right at my desk. Nice presentation. Covers a lot of stuff. – The UNIX man page has pretty much everything you want to know, albeit in a somewhat less accessible format. – Plenty of stuff online too. . . • Ruby – The book “Programming Ruby” by Thomas and Hunt is, I think, the standard tutorial/reference book. – The first edition of this book is mostly online: http://www.rubycentral.com/book/index.htm Note: the online chapters are not complete, but it’s still quite useful. – There is now (as of Oct 2004) a 2nd edition available. 12
  • 13. Other resources • You can look at some of my initialization files (in /cs/whuang): – .emacs Emacs initialization file loaded every time emacs starts. – .bashrc BASH initialization file loaded every time a new shell starts. My convention is to keep system-specific things in my .bashrc such as environment variable definitions. – .alias I source this file from my .bashrc. It contains stuff such as aliases and functions that I want on all my systems (e.g., SunOS at RPI, linux at home, and for cygwin (and linux) on my laptop) 13