SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scriptingvceder
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command ShellTushar B Kute
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTSjulien pauli
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxkishore1986
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script Amit Ghosh
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash scriptSimon Su
 
Using Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSXUsing Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSXPuppet
 

Tendances (20)

Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
x86
x86x86
x86
 
Module 02 Using Linux Command Shell
Module 02 Using Linux Command ShellModule 02 Using Linux Command Shell
Module 02 Using Linux Command Shell
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Linux Shell Basics
Linux Shell BasicsLinux Shell Basics
Linux Shell Basics
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Unix shell scripting tutorial
Unix shell scripting tutorialUnix shell scripting tutorial
Unix shell scripting tutorial
 
Bash shell
Bash shellBash shell
Bash shell
 
Unix practical file
Unix practical fileUnix practical file
Unix practical file
 
Vi Editor
Vi EditorVi Editor
Vi Editor
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
Quick start bash script
Quick start   bash scriptQuick start   bash script
Quick start bash script
 
Using Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSXUsing Puppet on Linux, Windows, and Mac OSX
Using Puppet on Linux, Windows, and Mac OSX
 
Ruby meetup ROM
Ruby meetup ROMRuby meetup ROM
Ruby meetup ROM
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 

Similaire à tools

Similaire à tools (20)

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
 
Unix
UnixUnix
Unix
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
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
 
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
 

Plus de 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
 

Plus de 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
 

Dernier

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

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