# use temporary files to store partial results # remember to delete these temporary files when you do not need them anymore

Similar documents
Shells & Shell Programming (Part B)

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

CS Unix Tools & Scripting

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Shell Scripting. Winter 2019

CS214 Advanced UNIX Lecture 4

Scripting. More Shell Scripts. Adapted from Practical Unix and Programming Hunter College

Scripting. More Shell Scripts Loops. Adapted from Practical Unix and Programming Hunter College

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Linux Shell Script. J. K. Mandal

CSE 15L Winter Midterm :) Review

Essentials for Scientific Computing: Bash Shell Scripting Day 3

LOG ON TO LINUX AND LOG OFF

Practical 02. Bash & shell scripting

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

Shell Programming Systems Skills in C and Unix

Basic Linux (Bash) Commands

"Bash vs Python Throwdown" -or- "How you can accomplish common tasks using each of these tools" Bash Examples. Copying a file: $ cp file1 file2

Useful Unix Commands Cheat Sheet

Bash Shell Programming Helps

Introduction to UNIX Command Line

The Unix Shell & Shell Scripts

INTRODUCTION TO SHELL SCRIPTING ITPART 2

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

2. UDP Client, UDP Server

SASGSUB for Job Workflow and SAS Log Files Piyush Singh, Prasoon Sangwan TATA Consultancy Services Ltd. Indianapolis, IN

Linux shell scripting Getting started *

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

Lesson 10 Using and Sorting Lists

for more :-

5/8/2012. Exploring Utilities Chapter 5

Exploring UNIX: Session 3

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi

COMP2100/2500 Lecture 17: Shell Programming II

Basic Shell Scripting Practice. HPC User Services LSU HPC & LON March 2018

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

Shell Scripting. With Applications to HPC. Edmund Sumbar Copyright 2007 University of Alberta. All rights reserved

CSE 374 Midterm Exam Sample Solution 2/6/12

IB047. Unix Text Tools. Pavel Rychlý Mar 3.

BASH Programming Introduction

UNIX System Programming Lecture 3: BASH Programming

Shell Programming (bash)

Shells and Shell Programming

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

CSE 303, Winter 2007, Midterm Examination 9 February Please do not turn the page until everyone is ready.

The Linux Command Line & Shell Scripting

Basics. proper programmers write commands

Open up a terminal, make sure you are in your home directory, and run the command.

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

Computer Systems and Architecture

Introduction To. Barry Grant

Part 1: Basic Commands/U3li3es

Bash Check If Command Line Parameter Exists

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

9.2 Linux Essentials Exam Objectives

Linux Essentials Objectives Topics:

Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

DAVE LIDDAMENT INTRODUCTION TO BASH

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala

A Brief Introduction to the Linux Shell for Data Science

Computer Systems and Architecture

Chapter 4. Unix Tutorial. Unix Shell

Shell Programming. Introduction to Linux. Peter Ruprecht Research CU Boulder

Shells and Shell Programming

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

LING 408/508: Computational Techniques for Linguists. Lecture 5

CS214-AdvancedUNIX. Lecture 2 Basic commands and regular expressions. Ymir Vigfusson. CS214 p.1

Name: Tej. D. Shah Subject:CC-304 Linux Uni. Practical programme College :L.J. College Of Computer Application. Questions:

Subcontractors. bc math help for the shell. interactive or programatic can accept its commands from stdin can accept an entire bc program s worth

Assignment 3, Due October 4

COMS 6100 Class Notes 3

Introduction to Shell Scripting

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

Introduction Into Linux Lecture 1 Johannes Werner WS 2017

CSCI 2132: Software Development

CENG 334 Computer Networks. Laboratory I Linux Tutorial

CSE 374 Midterm Exam 11/2/15 Sample Solution. Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

CS 124/LINGUIST 180 From Languages to Information

Introduction to Supercomputing

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

Assignment 2. Summary. Some Important bash Instructions. CSci132 Practical UNIX and Programming Assignment 2, Fall Prof.

CSNB113: System Administration - 8 th Topic: Shell Scripts Programming I

Consider the following program.

Answers to Even-numbered Exercises

NCAR-Developed Tools. Bill Anderson and Marc Genty National Center for Atmospheric Research HUF 2017

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

CENG393 Computer Networks Labwork 1

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

Lecture 5. Essential skills for bioinformatics: Unix/Linux

INTRODUCTION TO SHELL SCRIPTING Dr. Jeffrey Frey University of Delaware, IT

Linux command line basics III: piping commands for text processing. Yanbin Yin Fall 2015

CSE 374 Midterm Exam Sample Solution 2/11/13. Question 1. (8 points) What does each of the following bash commands do?

LPI Number: Passing Score: 800 Time Limit: 120 min File Version: 5. LPI Questions & Answers

SANJAY GHODAWAT POLYTECHNIC

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options

Transcription:

#!/bin/bash/ #Man entry # Script that reads a file and outputs a list of unique words # in the file, their frequency and total number # Usage: wsc.sh file finalres # This solution es not assume that we have a big file with all the words, without # duplications removed #End man entry # # use temporary files to store partial results # remember to delete these temporary files when you not need them anymore tempfile0=`mktemp` # test whether finalres exists # if not, run the ws.sh (here named words_stat2.sh) on file and finalres (the else branch) # if finalres exists, need to update it if [ -e "$2" ] then tempfile=`mktemp` bash words_stat2.sh $1 $tempfile 2> /dev/null # tempfile contains the words in the input file and their frequency # call this partial result # remove spaces at the beginning of a line (processing needed later for cut) echo "Partial result: " cat $tempfile

# finalc2 stores only the word column in the big statistics file finalc2=`mktemp` cut -d' ' -f2 $2 > $finalc2 # for this to work, need to remove spaces at the beginning of each line in $2 # go back

#!/bin/bash/ #Man entry # Script that reads a file and outputs a list of unique words # in the file, their frequency and total number # Usage: wsc.sh file finalres # This solution es not assume that we have a big file with all the words, without # duplications removed #End man entry # # use temporary files to store partial results # remember to delete these temporary files when you not need them anymore tempfile0=`mktemp` # test whether finalres exists # if not, run the ws.sh (here named words_stat2.sh) on file and finalres (the else branch) # if finalres exists, need to update it if [ -e "$2" ] then tempfile=`mktemp` bash words_stat2.sh $1 $tempfile 2> /dev/null # tempfile contains the words in the input file and their frequency # call this partial result # remove spaces at the beginning of a line (processing needed later for cut) sed 's/^ *//' $tempfile > $tempfile0 cp $tempfile0 $tempfile echo "Partial result: " cat $tempfile

# finalc2 stores only the word column in the big statistics file finalc2=`mktemp` cut -d' ' -f2 $2 > $finalc2 echo "Words in $2:" cat $finalc2 # tempc2 stores the word column in the partial result tempc2=`mktemp` cut -d' ' -f2 $tempfile > $tempc2 echo "Words in partial result:" cat $tempc2 # this where we start constructing the final result final=`mktemp` echo "Words in $2 and not in partial result:" echo "Words in partial result and not in $2:" echo "Words in both $2 and partial result:"

# finalc2 stores only the word column in the big statistics file finalc2=`mktemp` cut -d' ' -f2 $2 > $finalc2 echo "Words in $2:" cat $finalc2 # tempc2 stores the word column in the partial result tempc2=`mktemp` cut -d' ' -f2 $tempfile > $tempc2 echo "Words in partial result:" cat $tempc2 # this where we start constructing the final result final=`mktemp` echo "Words in $2 and not in partial result:" comm -23 $finalc2 $tempc2 echo "Words in partial result and not in $2:" comm -13 $finalc2 $tempc2 echo "Words in both $2 and partial result:" comm -12 $finalc2 $tempc2

# if s is a common word, its frequency in final is the sum of # the frequency of s in partial result and in statistics file for s in `comm -12 $finalc2 $tempc2` i=`cat $2 grep $s cut -d' ' -f1` j=`cat $tempfile grep $s cut -d' ' -f1` k=`expr $i + $j` echo $k $s echo "$k $s" >> $final # if s is a word in partial result but not in big statistics file, # then add its entry from the partial result to final for s in `comm -23 $finalc2 $tempc2` i=`cat $2 grep $s cut -d' ' -f1 ` echo $i $s echo "$i $s" >> $final # if s is a word in big statistics file but not in the partial result, # then add its entry from the statistics files to final for s in `comm -13 $finalc2 $tempc2` i=`cat $tempfile grep $s cut -d' ' -f1` echo $i $s echo "$i $s" >> $final

# if s is a common word, its frequency in final is the sum of # the frequency of s in partial result and in statistics file for s in `comm -12 $finalc2 $tempc2` s1="$s$" i=`cat $2 egrep " "$s1 cut -d' ' -f1` j=`cat $tempfile egrep " "$s1 cut -d' ' -f1` k=`expr $i + $j` echo $k $s echo "$k $s" >> $final # if s is a word in partial result but not in big statistics file, # then add its entry from the partial result to final for s in `comm -23 $finalc2 $tempc2` s1="$s$" i=`cat $2 egrep " "$s1 cut -d' ' -f1 ` echo $i $s echo "$i $s" >> $final # if s is a word in big statistics file but not in the partial result, # then add its entry from the statistics files to final for s in `comm -13 $finalc2 $tempc2` s1="$s$" i=`cat $tempfile egrep " "$s1 cut -d' ' -f1` echo $i $s echo "$i $s" >> $final

# finally, sort the final result based on the words (2nd column) sort -k 2 < $final > $2 rm $final rm $tempc2 rm $finalc2 rm $tempfile else bash words_stat2.sh $1 $2 sed 's/^ *//' $2 > $tempfile0 cp $tempfile0 $2 fi rm $tempfile0