Unix Shell Programming Is a Tutorial Aimed at Helping Unix and Linux Users Get Optimal Performance out of Their Operating out of Their Operating System

Total Page:16

File Type:pdf, Size:1020Kb

Unix Shell Programming Is a Tutorial Aimed at Helping Unix and Linux Users Get Optimal Performance out of Their Operating out of Their Operating System • Table of Contents • Index Unix® Shell Programming, Third Edition By Stephen G. Kochan, Patrick Wood Publisher: Sams Publishing Pub Date: February 27, 2003 ISBN: 0-672-32490-3 Pages: 456 Slots: 1 Unix Shell Programming is a tutorial aimed at helping Unix and Linux users get optimal performance out of their operating out of their operating system. It shows them how to take control of their systems and work efficiently by harnessing the power of the shell to solve common problems. The reader learns everything he or she needs to know to customize the way a Unix system responds. The vast majority of Unix users utilize the Korn shell or some variant of the Bourne shell, such as bash. Three are covered in the third edition of Unix Shell Programming. It begins with a generalized tutorial of Unix and tools and then moves into detailed coverage of shell programming. Topics covered include: regular expressions, the kernel and the utilities, command files, parameters, manipulating text filters, understanding and debugging shell scripts, creating and utilizing variables, tools, processes, and customizing the shell. • Table of Contents • Index Unix® Shell Programming, Third Edition By Stephen G. Kochan, Patrick Wood Publisher: Sams Publishing Pub Date: February 27, 2003 ISBN: 0-672-32490-3 Pages: 456 Slots: 1 Copyright About the Authors We Want to Hear from You! Reader Services Chapter 1. Introduction Chapter 2. A Quick Review of the Basics Some Basic Commands Working with Files Working with Directories Filename Substitution Standard Input/Output and I/O Redirection Pipes Standard Error More on Commands Command Summary Exercises Chapter 3. What Is the Shell? The Kernel and the Utilities The Login Shell Typing Commands to the Shell The Shell's Responsibilities Chapter 4. Tools of the Trade Regular Expressions cut paste sed tr grep sort uniq Exercises Chapter 5. And Away We Go Command Files Variables Built-in Integer Arithmetic Exercises Chapter 6. Can I Quote You on That? The Single Quote The Double Quote The Backslash Command Substitution Exercises Chapter 7. Passing Arguments The $# Variable The $* Variable A Program to Look Up Someone in the Phone Book A Program to Add Someone to the Phone Book A Program to Remove Someone from the Phone Book ${n} The shift Command Exercises Chapter 8. Decisions, Decisions Exit Status The test Command The else Construct The exit Command The elif Construct The case Command The Null Command : The && and || Constructs Exercises Chapter 9. 'Round and 'Round She Goes The for Command The until Command More on Loops The getopts Command Exercises Chapter 10. Reading and Printing Data The read Command The printf Command Exercises Chapter 11. Your Environment Local Variables Exported Variables PS1 and PS2 HOME, James Your PATH Your Current Directory More on Subshells Your .profile File The TERM Variable The TZ Variable Exercises Chapter 12. More on Parameters Parameter Substitution The $0 Variable The set Command The IFS Variable The readonly Command The unset Command Exercises Chapter 13. Loose Ends The eval Command The wait Command The trap Command More on I/O Functions The type Command Exercises Chapter 14. Rolo Revisited Design Considerations rolo add lu display rem change listall Sample Output Exercises Chapter 15. Interactive and Nonstandard Shell Features Getting the Right Shell The ENV File Command-Line Editing Command History The vi Line Edit Mode The Line Edit Mode Other Ways to Access Your History Functions Integer Arithmetic The alias Command Arrays Job Control The Restricted Shell rsh Miscellaneous Features Compatibility Summary Exercises Appendix A. Shell Summary Startup Commands Comments Parameters and Variables Command Re-entry Quoting Filename Substitution I/O Redirection Exported Variables and Subshell Execution Functions Job Control Command Summary Appendix B. For More Information Online Documentation Documentation on the Web Books Index Copyright Copyright © 2003 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein. Library of Congress Catalog Card Number: 2002115932 Printed in the United States of America First Printing: March 2003 06 05 04 03 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an "as is" basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book. Credits Acquisitions Editor Katie Purdum Development Editor Scott Meyers Managing Editor Charlotte Clapp Copy Editor Geneil Breeze Indexer Erika Millen Proofreader Jessica McCarty Technical Editor Michael Watson Interior Designer Gary Adair Cover Designer Gary Adair Page Layout Susan Geiselman Dedication To my father, Harry Wood —Patrick Wood To Gregory, Linda, and Julia for giving meaning to my life —Stephen G. Kochan About the Authors Stephen G. Kochan is the owner of TechFitness, a technology-based fitness company. Prior to that, he was president and CEO of Pipeline Associates, a company specializing in color printing software. Mr. Kochan is the author of several best-selling books on Unix and C programming, including the best-selling Programming in C. He also acted as Series Editor for the Hayden Unix System Library. Patrick Wood is the CTO of the New Jersey location of Electronics for Imaging. He was a member of the technical staff at Bell Laboratories when he met Mr. Kochan in 1985. Together they founded Pipeline Associates, Inc., a Unix consulting firm, where he was the Vice President. They coauthored Exploring the Unix System, Unix System Security, Topics in C Programming, and Unix Shell Programming. We Want to Hear from You! As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can email or write me directly to let me know what you did or didn't like about this book—as well as what we can do to make our books stronger. Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message. When you write, please be sure to include this book's title and author as well as your name and phone or email address. I will carefully review your comments and share them with the author and editors who worked on the book. Email: [email protected] Mail: Mark Taber Associate Publisher Sams Publishing 201 West 103rd Street Indianapolis, IN 46290 USA Reader Services For more information about this book or others from Sams Publishing, visit our Web site at www. samspublishing.com. Type the ISBN (excluding hyphens) or the title of the book in the Search box to find the book you're looking for. Chapter 1. Introduction It's no secret that the Unix operating system has emerged as a standard operating system. For programmers who have been using Unix for many years now, this came as no surprise: The Unix system provides an elegant and efficient environment for program development. After all, this is what Dennis Ritchie and Ken Thompson strived for when they developed Unix at Bell Laboratories in the late 1960s. One of the strongest features of the Unix system is its wide collection of programs. More than 200 basic commands are distributed with the standard operating system. These commands (also known as tools) do everything from counting the number of lines in a file, to sending electronic mail, to displaying a calendar for any desired year. But the real strength of the Unix system comes not entirely from this large collection of commands but also from the elegance and ease with which these commands can be combined to perform far more sophisticated functions. To further this end, and also to provide a consistent buffer between the user and the guts of the Unix system (the kernel), the shell was developed. The shell is simply a program that reads in the commands you type and converts them into a form more readily understood by the Unix system. It also includes some fundamental programming constructs that let you make decisions, loop, and store values in variables. The standard shell distributed with Unix and Linux systems derives from AT&T's distribution, which evolved from a version originally written by Stephen Bourne at Bell Labs. Since then, the IEEE created standards based on the Bourne shell and the other more recent shells. The current version of this standard as of this revision is the Shell and Utilities volume of IEEE Std 1003.1-2001, also known as the POSIX standard. This shell is what we propose to teach you about in this book.
Recommended publications
  • Shell Scripting with Bash
    Introduction to Shell Scripting with Bash Charles Jahnke Research Computing Services Information Services & Technology Topics for Today ● Introductions ● Basic Terminology ● How to get help ● Command-line vs. Scripting ● Variables ● Handling Arguments ● Standard I/O, Pipes, and Redirection ● Control Structures (loops and If statements) ● SCC Job Submission Example Research Computing Services Research Computing Services (RCS) A group within Information Services & Technology at Boston University provides computing, storage, and visualization resources and services to support research that has specialized or highly intensive computation, storage, bandwidth, or graphics requirements. Three Primary Services: ● Research Computation ● Research Visualization ● Research Consulting and Training Breadth of Research on the Shared Computing Cluster (SCC) Me ● Research Facilitator and Administrator ● Background in biomedical engineering, bioinformatics, and IT systems ● Offices on both CRC and BUMC ○ Most of our staff on the Charles River Campus, some dedicated to BUMC ● Contact: [email protected] You ● Who has experience programming? ● Using Linux? ● Using the Shared Computing Cluster (SCC)? Basic Terminology The Command-line The line on which commands are typed and passed to the shell. Username Hostname Current Directory [username@scc1 ~]$ Prompt Command Line (input) The Shell ● The interface between the user and the operating system ● Program that interprets and executes input ● Provides: ○ Built-in commands ○ Programming control structures ○ Environment
    [Show full text]
  • System Calls and I/O
    System Calls and I/O CS 241 January 27, 2012 Copyright ©: University of Illinois CS 241 Staff 1 This lecture Goals Get you familiar with necessary basic system & I/O calls to do programming Things covered in this lecture Basic file system calls I/O calls Signals Note: we will come back later to discuss the above things at the concept level Copyright ©: University of Illinois CS 241 Staff 2 System Calls versus Function Calls? Copyright ©: University of Illinois CS 241 Staff 3 System Calls versus Function Calls Function Call Process fnCall() Caller and callee are in the same Process - Same user - Same “domain of trust” Copyright ©: University of Illinois CS 241 Staff 4 System Calls versus Function Calls Function Call System Call Process Process fnCall() sysCall() OS Caller and callee are in the same Process - Same user - OS is trusted; user is not. - Same “domain of trust” - OS has super-privileges; user does not - Must take measures to prevent abuse Copyright ©: University of Illinois CS 241 Staff 5 System Calls System Calls A request to the operating system to perform some activity System calls are expensive The system needs to perform many things before executing a system call The computer (hardware) saves its state The OS code takes control of the CPU, privileges are updated. The OS examines the call parameters The OS performs the requested function The OS saves its state (and call results) The OS returns control of the CPU to the caller Copyright ©: University of Illinois CS 241 Staff 6 Steps for Making a System Call
    [Show full text]
  • Passive Asset Discovery and Operating System Fingerprinting in Industrial Control System Networks
    Eindhoven University of Technology MASTER Passive asset discovery and operating system fingerprinting in industrial control system networks Mavrakis, C. Award date: 2015 Link to publication Disclaimer This document contains a student thesis (bachelor's or master's), as authored by a student at Eindhoven University of Technology. Student theses are made available in the TU/e repository upon obtaining the required degree. The grade received is not published on the document as presented in the repository. The required complexity or quality of research of student theses may vary by program, and the required minimum study period may vary in duration. General rights Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain Department of Mathematics and Computer Science Passive Asset Discovery and Operating System Fingerprinting in Industrial Control System Networks Master Thesis Chris Mavrakis Supervisors: prof.dr. S. Etalle dr. T. Oz¸celebi¨ dr. E. Costante Eindhoven, October 2015 Abstract Maintaining situational awareness in networks of industrial control systems is challenging due to the sheer number of devices involved, complex connections between subnetworks and the delicate nature of industrial processes. While current solutions for automatic discovery of devices and their operating system are lacking, plant operators need to have accurate information about the systems to be able to manage them effectively and detect, prevent and mitigate security and safety incidents.
    [Show full text]
  • Teach Yourself Data Structures and Algorithms in 24 Hours
    TeamLRN 00 72316331 FM 10/31/02 6:54 AM Page i Robert Lafore Teach Yourself Data Structures and Algorithms in24 Hours 201 West 103rd St., Indianapolis, Indiana, 46290 USA 00 72316331 FM 10/31/02 6:54 AM Page ii Sams Teach Yourself Data Structures and EXECUTIVE EDITOR Algorithms in 24 Hours Brian Gill DEVELOPMENT EDITOR Copyright © 1999 by Sams Publishing Jeff Durham All rights reserved. No part of this book shall be reproduced, stored in a MANAGING EDITOR retrieval system, or transmitted by any means, electronic, mechanical, photo- Jodi Jensen copying, recording, or otherwise, without written permission from the pub- lisher. No patent liability is assumed with respect to the use of the information PROJECT EDITOR contained herein. Although every precaution has been taken in the preparation Tonya Simpson of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use COPY EDITOR of the information contained herein. Mike Henry International Standard Book Number: 0-672-31633-1 INDEXER Larry Sweazy Library of Congress Catalog Card Number: 98-83221 PROOFREADERS Printed in the United States of America Mona Brown Jill Mazurczyk First Printing: May 1999 TECHNICAL EDITOR 01 00 99 4 3 2 1 Richard Wright Trademarks SOFTWARE DEVELOPMENT All terms mentioned in this book that are known to be trademarks or service SPECIALIST marks have been appropriately capitalized. Sams Publishing cannot attest to Dan Scherf the accuracy of this information. Use of a term in this book should not be INTERIOR DESIGN regarded as affecting the validity of any trademark or service mark.
    [Show full text]
  • Use Perl Regular Expressions in SAS® Shuguang Zhang, WRDS, Philadelphia, PA
    NESUG 2007 Programming Beyond the Basics Use Perl Regular Expressions in SAS® Shuguang Zhang, WRDS, Philadelphia, PA ABSTRACT Regular Expression (Regexp) enhance search and replace operations on text. In SAS®, the INDEX, SCAN and SUBSTR functions along with concatenation (||) can be used for simple search and replace operations on static text. These functions lack flexibility and make searching dynamic text difficult, and involve more function calls. Regexp combines most, if not all, of these steps into one expression. This makes code less error prone, easier to maintain, clearer, and can improve performance. This paper will discuss three ways to use Perl Regular Expression in SAS: 1. Use SAS PRX functions; 2. Use Perl Regular Expression with filename statement through a PIPE such as ‘Filename fileref PIPE 'Perl programm'; 3. Use an X command such as ‘X Perl_program’; Three typical uses of regular expressions will also be discussed and example(s) will be presented for each: 1. Test for a pattern of characters within a string; 2. Replace text; 3. Extract a substring. INTRODUCTION Perl is short for “Practical Extraction and Report Language". Larry Wall Created Perl in mid-1980s when he was trying to produce some reports from a Usenet-Nes-like hierarchy of files. Perl tries to fill the gap between low-level programming and high-level programming and it is easy, nearly unlimited, and fast. A regular expression, often called a pattern in Perl, is a template that either matches or does not match a given string. That is, there are an infinite number of possible text strings.
    [Show full text]
  • A First Course to Openfoam
    Basic Shell Scripting Slides from Wei Feinstein HPC User Services LSU HPC & LON [email protected] September 2018 Outline • Introduction to Linux Shell • Shell Scripting Basics • Variables/Special Characters • Arithmetic Operations • Arrays • Beyond Basic Shell Scripting – Flow Control – Functions • Advanced Text Processing Commands (grep, sed, awk) Basic Shell Scripting 2 Linux System Architecture Basic Shell Scripting 3 Linux Shell What is a Shell ▪ An application running on top of the kernel and provides a command line interface to the system ▪ Process user’s commands, gather input from user and execute programs ▪ Types of shell with varied features o sh o csh o ksh o bash o tcsh Basic Shell Scripting 4 Shell Comparison Software sh csh ksh bash tcsh Programming language y y y y y Shell variables y y y y y Command alias n y y y y Command history n y y y y Filename autocompletion n y* y* y y Command line editing n n y* y y Job control n y y y y *: not by default http://www.cis.rit.edu/class/simg211/unixintro/Shell.html Basic Shell Scripting 5 What can you do with a shell? ▪ Check the current shell ▪ echo $SHELL ▪ List available shells on the system ▪ cat /etc/shells ▪ Change to another shell ▪ csh ▪ Date ▪ date ▪ wget: get online files ▪ wget https://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz ▪ Compile and run applications ▪ gcc hello.c –o hello ▪ ./hello ▪ What we need to learn today? o Automation of an entire script of commands! o Use the shell script to run jobs – Write job scripts Basic Shell Scripting 6 Shell Scripting ▪ Script: a program written for a software environment to automate execution of tasks ▪ A series of shell commands put together in a file ▪ When the script is executed, those commands will be executed one line at a time automatically ▪ Shell script is interpreted, not compiled.
    [Show full text]
  • Bash Crash Course + Bc + Sed + Awk∗
    Bash Crash course + bc + sed + awk∗ Andrey Lukyanenko, CSE, Aalto University Fall, 2011 There are many Unix shell programs: bash, sh, csh, tcsh, ksh, etc. The comparison of those can be found on-line 1. We will primary focus on the capabilities of bash v.4 shell2. 1. Each bash script can be considered as a text file which starts with #!/bin/bash. It informs the editor or interpretor which tries to open the file, what to do with the file and how should it be treated. The special character set in the beginning #! is a magic number; check man magic and /usr/share/file/magic on existing magic numbers if interested. 2. Each script (assume you created “scriptname.sh file) can be invoked by command <dir>/scriptname.sh in console, where <dir> is absolute or relative path to the script directory, e.g., ./scriptname.sh for current directory. If it has #! as the first line it will be invoked by this command, otherwise it can be called by command bash <dir>/scriptname.sh. Notice: to call script as ./scriptname.sh it has to be executable, i.e., call command chmod 555 scriptname.sh before- hand. 3. Variable in bash can be treated as integers or strings, depending on their value. There are set of operations and rules available for them. For example: #!/bin/bash var1=123 # Assigns value 123 to var1 echo var1 # Prints ’var1’ to output echo $var1 # Prints ’123’ to output var2 =321 # Error (var2: command not found) var2= 321 # Error (321: command not found) var2=321 # Correct var3=$var2 # Assigns value 321 from var2 to var3 echo $var3 # Prints ’321’ to output
    [Show full text]
  • Institutionen För Datavetenskap Department of Computer and Information Science
    Institutionen för datavetenskap Department of Computer and Information Science Final thesis NetworkPerf – A tool for the investigation of TCP/IP network performance at Saab Transpondertech by Magnus Johansson LIU-IDA/LITH-EX-A--09/039--SE 2009-08-13 Linköpings universitet Linköpings universitet SE-581 83 Linköping, Sweden 581 83 Linköping Final thesis NetworkPerf - A tool for the investigation of TCP/IP network performance at Saab Transpondertech Version 1.0.2 by Magnus Johansson LIU-IDA/LITH-EX-A09/039SE 2009-08-13 Supervisor: Hannes Persson, Attentec AB Examiner: Dr Juha Takkinen, IDA, Linköpings universitet Abstract In order to detect network changes and network troubles, Saab Transpon- dertech needs a tool that can make network measurements. The purpose of this thesis has been to nd measurable network proper- ties that best reect the status of a network, to nd methods to measure these properties and to implement these methods in one single tool. The resulting tool is called NetworkPerf and can measure the following network properties: availability, round-trip delay, delay variation, number of hops, intermediate hosts, available bandwidth, available ports, and maximum al- lowed packet size. The thesis also presents the methods used for measuring these properties in the tool: ping, traceroute, port scanning, and bandwidth measurement. iii iv Acknowledgments This master's thesis would not be half as good as it is, if I had not received help and support from several people. Many thanks to my examiner Dr Juha Takkinen, without whose countin- uous feedback this report would not have been more than a few confusing pages.
    [Show full text]
  • Praat Scripting Tutorial
    Praat Scripting Tutorial Eleanor Chodroff Newcastle University July 2019 Praat Acoustic analysis program Best known for its ability to: Visualize, label, and segment audio files Perform spectral and temporal analyses Synthesize and manipulate speech Praat Scripting Praat: not only a program, but also a language Why do I want to know Praat the language? AUTOMATE ALL THE THINGS Praat Scripting Why can’t I just modify others’ scripts? Honestly: power, flexibility, control Insert: all the gifs of ‘you can do it’ and ‘you got this’ and thumbs up Praat Scripting Goals ~*~Script first for yourself, then for others~*~ • Write Praat scripts quickly, effectively, and “from scratch” • Learn syntax and structure of the language • Handle various input/output combinations Tutorial Overview 1) Praat: Big Picture 2) Getting started 3) Basic syntax 4) Script types + Practice • Wav files • Measurements • TextGrids • Other? Praat: Big Picture 1) Similar to other languages you may (or may not) have used before • String and numeric variables • For-loops, if else statements, while loops • Regular expression matching • Interpreted language (not compiled) Praat: Big Picture 2) Almost everything is a mouse click! i.e., Praat is a GUI scripting language GUI = Graphical User Interface, i.e., the Objects window If you ever get lost while writing a Praat script, click through the steps using the GUI Getting Started Open a Praat script From the toolbar, select Praat à New Praat script Save immediately! Save frequently! Script Goals and Input/Output • Consider what
    [Show full text]
  • 'Unix' in a File
    ============================ AWK COMMANDS ================================ 1) find the total occurances of pattern of 'unix' in a file. ==> $awk '/unix/ {count++} END{print count}' nova.txt 2) find the total line of a file. ==> $awk 'END{print NR}' nova.txt 3) print the total number of even line of a file. ==> $awk 'NR % 2' nova.txt 4) print the total number of odd line of a file. ==> $awk 'NR % 2 == 1' nova.txt 5) print the sums of the field of every line of a file. ==> $awk '{ sum = $3+sum } END{print sum}' emp.txt 6) display those words whose length greater than 10 and consist of digits only in file awk ==> $awk '/^[0-9]+$/ length<10 {print}' t3.txt 7) display those words whose length less than 10 and consist of alpha only in file awk ==> $awk '/^[a-zA-Z]+$/ length >3 {print}' t3.txt 8) print odd number of word in each line ==> awk -F\| '{s="";for (i=1;i<=NF;i+=2) { {s=s? $i:$i} print s }}' nova.txt { s = ""; for (i = 1; i <= NF; i+=2) { s = s ? $i : $i } print s } 9) print even number of word in each line ==> awk -F\| '{s="";for (i=0;i<=NF;i+=2) { {s=s? $i:$i} print s }}' nova.txt ==> { s = ""; for (i = 0; i <= NF; i+=2) { s = s ? $i : $i } print s } 10) print the last character of a string using awk ==> awk '{print substr($0,length($0),1)}' nova.txt ============================ MIX COMMANDS ================================ 1) Assign value of 10th positional parameter to 1 variable x. ==> x=${10} 2) Display system process; ==> ps -e ==> ps -A 3) Display number of process; ==> ps aux 4) to run a utility x1 at 11:00 AM ==> at 11:00 am x1 5) Write a command to print only last 3 characters of a line or string.
    [Show full text]
  • Useful Commands in Linux and Other Tools for Quality Control
    Useful commands in Linux and other tools for quality control Ignacio Aguilar INIA Uruguay 05-2018 Unix Basic Commands pwd show working directory ls list files in working directory ll as before but with more information mkdir d make a directory d cd d change to directory d Copy and moving commands To copy file cp /home/user/is . To copy file directory cp –r /home/folder . to move file aa into bb in folder test mv aa ./test/bb To delete rm yy delete the file yy rm –r xx delete the folder xx Redirections & pipe Redirection useful to read/write from file !! aa < bb program aa reads from file bb blupf90 < in aa > bb program aa write in file bb blupf90 < in > log Redirections & pipe “|” similar to redirection but instead to write to a file, passes content as input to other command tee copy standard input to standard output and save in a file echo copy stream to standard output Example: program blupf90 reads name of parameter file and writes output in terminal and in file log echo par.b90 | blupf90 | tee blup.log Other popular commands head file print first 10 lines list file page-by-page tail file print last 10 lines less file list file line-by-line or page-by-page wc –l file count lines grep text file find lines that contains text cat file1 fiel2 concatenate files sort sort file cut cuts specific columns join join lines of two files on specific columns paste paste lines of two file expand replace TAB with spaces uniq retain unique lines on a sorted file head / tail $ head pedigree.txt 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10
    [Show full text]
  • 5 Command Line Functions by Barbara C
    ADAPS: Chapter 5. Command Line Functions 5 Command Line Functions by Barbara C. Hoopes and James F. Cornwall This chapter describes ADAPS command line functions. These are functions that are executed from the UNIX command line instead of from ADAPS menus, and that may be run manually or by automated means such as “cron” jobs. Most of these functions are NOT accessible from the ADAPS menus. These command line functions are described in detail below. 5.1 Hydra Although Hydra is available from ADAPS at the PR sub-menu, Edit Time Series Data using Hydra (TS_EDIT), it can also be started from the command line. However, to start Hydra outside of ADAPS, a DV or UV RDB file needs to be available to edit. The command is “hydra rdb_file_name.” For a complete description of using Hydra, refer to Section 4.5.2 Edit Time-Series Data using Hydra (TS_EDIT). 5.2 nwrt2rdb This command is used to output rating information in RDB format. It writes RDB files with a table containing the rating equation parameters or the rating point pairs, with all other information contained in the RDB comments. The following arguments can be used with this command: nwrt2rdb -ooutfile -zdbnum -aagency -nstation -dddid -trating_type -irating_id -e (indicates to output ratings in expanded form; it is ignored for equation ratings.) -l loctzcd (time zone code or local time code "LOC") -m (indicates multiple output files.) -r (rounding suppression) Rules • If -o is omitted, nwrt2rdb writes to stdout; AND arguments -n, -d, -t, and -i must be present. • If -o is present, no other arguments are required, and the program will use ADAPS routines to prompt for them.
    [Show full text]