6a.1 More about files: Globbing. 6a.2 Open a file for reading, and link it to a filehandle: open(IN, "<EHD.fasta"); And then read lines from the filehandle,

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

DOS & Windows O/s Prof. Sujata Rao Less 5.
Operating System Type of Operating System
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
COMP234 Perl Printing Special Quotes File Handling.
4.1 Reading and writing files. 4.2 Open a file for reading, and link it to a filehandle: open(IN, "
DIR : Displays a list of files and subdirectories in a directory. Syntax: DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] /P.
Perl File and Directory Access Learning Objectives: 1. To learn how to change directories being accessed in a Perl program 2. To learn the Perl’s command.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
Perl File I/O Learning Objectives: 1. To understand the usage of file handler in Perl 2. To learn the file error handling / testing in Perl.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Perl File and Directory Access Software Tools. Slide 2 Changing Directories You can change the current working directory within Perl, just like the cd.
“DOS is dead, (long live the command line)“ Source for most of this material: –
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
5.1 Previously on... PERL course (let ’ s practice some more loops)
Perl File I/O Software Tools. Slide 2 Filehandles l A filehandle is the name for an I/O connection between your Perl program and the outside world. STDIN.
Perl File and Directory Access Learning Objectives: 1. To learn how to change directories being accessed in a Perl program 2. To learn the Perl’s command.
1ex.1 Perl Programming for Biology Exercise 1 The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman.
4.1 Revision. 4.2 if, elsif, else It’s convenient to test several conditions in one if structure: print "Please enter your grades average:\n"; my $number.
I/O while ($line= ){ #remove new line char \n chomp($line); if($line eq “quit”){ exit(1); } while ( ){ #remove new line char \n chomp($_); if($_ eq “quit”){
Operating System Fundamentals
Using Unix Shell Scripts to Manage Large Data
Ch 61 Using DEL, REN, MOVE, and RD /S. Ch 62 Overview Will continue to work with internal commands that help manage and manipulate files.
1 THE UNIX FILE SYSTEM By Chokechai Chuensukanant ID COSC 513 Operating System.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Script M-Files Group of Matlab commands placed in a text file with a text editor. Matlab can open and execute the commands exactly as if they were entered.
3.1 Revision: variables & arrays Array declaration Array = ('A','B','C','D'); = = (); Array.
Chapter 9: Perl (continue) Advanced Perl Programming Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
1.  Microsoft DOS (Disk Operating System) use a command line user interface.command line  A command line user interface means that the user is required.
5 1 Data Files CGI/Perl Programming By Diane Zak.
DOS and the Command Line CS 21a: Introduction to Computing I First Semester,
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Random Bits of Perl None of this stuff is worthy of it’s own lecture, but it’s all a bunch of things you should learn to use Perl well.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
Operating System Fundamentals 1. Components of an OS 2. Functions of an OS 3. Types of OS 4. Command-line tools.
Linux Lecture #02. File Related Commands cat --Concatenate and print (display) the content of files. --Also used to create a new file. Syntax cat [Options]
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
Basic DOS How to get some work done. It’s all a file Everything is a file: OS files, Application files, Data files and Game files Files have 8.3 names:
PHP-5- Working with Files and Directories. Reading Files PHP’s file manipulation API is extremely flexible: it lets you read files into a string or into.
Agenda The Bourne Shell – Part II Special Characters Ambiguous File Reference Variable Names and Values User Created Variables Read-only Variables (Positional.
PTA Linux Series Copyright Professional Training Academy, CSIS, University of Limerick, 2006 © Workshop III - Part B Shell Commands Professional Training.
The Unix File sytem. Introduction Tree structure …
EMT 2390L Lecture 3 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Shell Scripting What is Shell Programming? Putting UNIX commands in a file Seldom used where speed is important Often used to manipulate files To create.
The Scripting Programming Language
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
1 © 2012 John Urrutia. All rights reserved. Chapter 09 The TC Shell.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Linux Administration Working with the BASH Shell.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
MS-DOS is an acronym for MicroSoft Disk Operating System It is a CUI based operating system. It provides user with a command prompt (generally called.
CIRC Summer School 2016 Baowei Liu
Fundamentals of Python: First Programs
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
CIRC Summer School 2017 Baowei Liu
CIRC Winter Boot Camp 2017 Baowei Liu
Introduction to Operating Systems
CIRC Summer School 2017 Baowei Liu
Basic Input/Output Web Programming.
Cmdlets “Command-lets”
The Linux Command Line Chapter 4
Module 6 Working with Files and Directories
The Linux Command Line Chapter 4
Presentation transcript:

6a.1 More about files: Globbing

6a.2 Open a file for reading, and link it to a filehandle: open(IN, "<EHD.fasta"); And then read lines from the filehandle, exactly like you would from : my $line = ; = ; foreach $line Every filehandle opened should be closed: close(IN); Always check the open didn ’ t fail (e.g. if a file by that name doesn ’ t exists): open(IN, "<$file") or die "can't open file $file"; Reminder: Reading files

6a.3 Open a file for writing, and link it to a filehandle: open(OUT, ">EHD.analysis") or die... NOTE: If a file by that name already exists it will be overwriten! You could append lines to the end of an existing file: open(OUT, ">>EHD.analysis") or die.. Print to a file (in both cases): print OUT "The mutation is in exon $exonNumber\n"; Reminder: Writing to files no comma here

6a.4 Perl allows easy access to the files in a directory by “ globbing ” : In globbing - the * represents any string character. For example, *.* represents all filenames. Note: the “ glob ” gives a list of the file names in the directory. = ; foreach my $fileName { open(IN, $fileName) or die "can't open file $fileName"; = ; foreach my $line { do something... } } Reading directories no " here

6a.5 You can interpolate variables in the glob, as in double-quoted = ; If $lesson is 4 then we may get these files : class_ex4.pl class_ex4.1.pl class_ex4.2.pl Reading directories

6a.6 Delete a file: unlink ("fred.txt") or die "can't delete fred.txt"; Delete all files in a directory whose name matches a certain “ pattern ” : unlink or die "can't delete files in fred"; (Here – all file names that end with “.txt ” ) Move/rename files: rename ("fred.txt", "friends\\bob.txt") or die "can't move fred.txt"; Manipulating files

6a.7 Generally, you can execute any command of the operating system: $systemReturn = system("del fred.txt"); Or: $systemReturn = system("copy fred.txt george.txt"); When checking the value returned by a system call, usually 0 means no errors: if ($systemReturn != 0) { die "can't copy fred.txt"; } Calling system commands

6a.8 Common DOS commands: copy Copies one or more files to another location. rename Renames a file or files. del Deletes one or more files md my_dir Make a new directory cd my_dir Change directory rd my_dir Removes a directory. help List all dos commands help dir Get help on a dos command Some system commands

6a.9 Class exercise 6a 1.Write a script that prints all the file names in “C:\Perl\lib\”, which their names end with ".pl", to a file named “C:\eclipse\perl_ex\perlFiles.txt". 2*.Change the script of the previous question, such that the directory name and the output file are passed as command-line arguments. 3*. Change the previous script, such that after creating the output file, it is copied to another file, whose name is also passed as a command-line argument.