Awk challanges Prof. Andrzej (AJ) Bieszczad Phone: 818-677-49541 awk Challenges Find out what the following awk scripts do: END.

Slides:



Advertisements
Similar presentations
Awk 1 – an introduction. Your scripts I will put them on the shared drive. Different solutions – diversity Title of (lab or question) Efficient?
Advertisements

While loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas.
UNIX Chapter 10 Advanced File Processing Mr. Mohammad Smirat.
CS252: Systems Programming Ninghui Li Program Interview Questions.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
1 Unix Talk #2 AWK overview Patterns and actions Records and fields Print vs. printf.
Need for Arrays Exercise Read the IDs and the grades for all ICS 101 students. Compute and print the average of the students. Print the grades and IDs.
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 6.
CSC 4630 Meeting 9 February 14, 2007 Valentine’s Day; Snow Day.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Lecture 5 sed and awk. Last week Regular Expressions –grep (BRE) –egrep (ERE) Sed - Part I.
Lecture 5 Awk and Shell. Sed Drawbacks Hard to remember text from one line to another Not possible to go backward in the file No way to do forward references.
Lecture 5 sed and awk. Last week Regular Expressions –grep –egrep.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Stream-Oriented, Non-Interactive EDitor sed Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and.
Sed and awk.
Programming Training Main Points: - Lists / Arrays in Python. - Fundamental algorithms on Arrays.
A Guide to Unix Using Linux Fourth Edition
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
Recursion A method is recursive if it makes a call to itself. A method is recursive if it makes a call to itself. For example: For example: public void.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
CS 403: Programming Languages Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Programming Languages Meeting 13 December 2/3, 2014.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Introduction to Awk Awk is a convenient and expressive programming language that can be applied to a wide variety of computing and data manipulation tasks.
Programmable Text Processing with awk Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users”
Strings CS303E: Elements of Computers and Programming.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Exam Revision Ruibin Bai (Room AB326) Division of Computer Science The University of Nottingham.
Perl Challenge Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Awk Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
13 More Advanced Awk Mauro Jaskelioff (originally by Gail Hopkins)
1 P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Awk Programming (2) Ruibin Bai (Room AB326) Division of Computer Science The University.
© 2006 KDnuggets [16/Nov/2005:16:32: ] "GET /jobs/ HTTP/1.1" "
16-Dec-15Advanced Programming Spring 2002 sed and awk Henning Schulzrinne Dept. of Computer Science Columbia University.
CVS: Concurrent Version System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
CSCI 330 UNIX and Network Programming
4.7 Triangle Inequalities. In any triangle…  The LARGEST SIDE lies opposite the LARGEST ANGLE.  The SMALLEST SIDE lies opposite the SMALLEST ANGLE.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 4 Karsten Hokamp, PhD Genetics TCD, 01/12/2015.
1 P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Awk Programming Ruibin Bai (Room AB326) Division of Computer Science The University.
Alon Efrat Computer Science Department University of Arizona Unix Tools.
CISC 1480/KRF Copyright © 1999 by Kenneth R. Frazer 1 AWK q A programming language for handling common data manipulation tasks with only a few lines of.
Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
Sed. Class Issues vSphere Issues – root only until lab 3.
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
CSCI 330 UNIX and Network Programming Unit IX: awk II.
UNIX commands Head More (press Q to exit) Cat – Example cat file – Example cat file1 file2 Grep – Grep –v ‘expression’ – Grep –A 1 ‘expression’ – Grep.
By Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
Programming Training Main Points: - More Fundamental algorithms on Arrays. - Reading / Writing from files - Problem Solving.
Awk- An Advanced Filter by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Programming Languages Meeting 12 November 18/19, 2014.
Awk 2 – more awk. AWK INVOCATION AND OPERATION the "-F" option allows changing Awk's "field separator" character. Awk regards each line of input data.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Awk Programmable Filters 1.
Languages Prof. Busch - LSU.
CS 403: Programming Languages
Recursion.
Guide To UNIX Using Linux Third Edition
INC 161 , CPE 100 Computer Programming
LING 408/508: Computational Techniques for Linguists
1.6) Storing Integer:.
Programming Training Main Points:
Class Examples.
Programming Languages
Sed and awk.
Awk.
1.6) Storing Integer: 1.7) storing fraction:
Presentation transcript:

awk challanges Prof. Andrzej (AJ) Bieszczad Phone: awk Challenges Find out what the following awk scripts do: END { print NR } Print number of records in a file. NR == 10 Print the 10th record of a file. { print $NF } { field = $NF } END { print field } Print all last fields in a file (i.e., last field of each record). NF > 4 Print records of a file that contain more than 4 fields. $NF > 4 { nf = nf + NF } END { print nf } Print number of fields in all records in which the fourth field is larger than 4.

awk challanges Prof. Andrzej (AJ) Bieszczad Phone: awk Challenges Hint: Use the following to try things out: $ awk ‘/one/{print “This line contains \”one\”.”}’ I’ve got one penny. This line contains “one”. Count all records that include string “->” /->/ { nlines = nlines + 1 } END { print nlines } Find the maximum value of the first field of all records and print it along with the whole record $1 > max { max = $1; maxline = $0 } END { print max, maxline }

awk challanges Prof. Andrzej (AJ) Bieszczad Phone: awk Challenges Print all records that are not empty NF > 0 Print all records that are longer than 80 characters length($0) > 80 Print the number of fields in each record along with the record { print NF, $0 } Print all records with reversed first two fields { print $2, $1 } { temp = $1; $1 = $2; $2 = temp; print } Remove the second field from all records { $2 = ""; print }

awk challanges Prof. Andrzej (AJ) Bieszczad Phone: awk Challenges Print all records backwards { for (i = NF; i > 0; i = i - 1) printf(“%s “, $i) printf(“\n”) } Compute and print a sum of all fields in each record { sum = 0 for (i = 1; i <= NF; i = i + 1) sum = sum + $i print sum } Compute and print a concatenation of all fields in whole file { for (i = 1; i <= NF; i = i + 1) sum = sum $i } END { print sum }