Professional Documents
Culture Documents
Acknowledgement: Mr.S.B.Shah For Allowing Me To Carry Out My Project at Their Esteemed Organization
Acknowledgement: Mr.S.B.Shah For Allowing Me To Carry Out My Project at Their Esteemed Organization
The best support I got from my institute was its tag which was behind my name. I think
without my college support I will not be able to even think about working in such an
esteemed organization.
The internship opportunity I had with ONGC was a great chance for learning and
professional development. Therefore, I consider myself as a very lucky individual as I was
provided with an opportunity to be a part of it. I am also grateful for having a chance to meet
so many wonderful people and professionals who led me though this internship period.
I express my deepest thanks to Mr.U.S. Pandey DGM (CGS Programming) for taking part
in useful decision & giving necessary advices and guidance and arranged all facilities to
make life easier.
I perceive as this opportunity as a big milestone in my career development. I will strive to use
gained skills and knowledge in the best possible way, and I will continue to work on their
improvement, in order to attain desired career objectives. Hope to continue cooperation with
all of you in the future.
AISHWARYA PRAKASH
CENTRAL UNIVERSITY OF RAJASTHAN
ROLL NO. 2016MSCS001
DATE-: 15TH FEB 2018
PLACE-: O.N.G.C Priyadarshani, Mumbai
INTRODUCTION
Since my joining of the winter training programme on 14th December 2017 which has
spanned over eight weeks, I have had the opportunity to work on the development of a wide
array of technical projects which are system-based. Over the course of my training, I have
learnt various aspects of professional software development like secure coding practices
adhering to the latest industry standards, writing tests to break and fix code and most
importantly to write quality code. I also learned some basics of the Linux operating system
(Ubuntu) and I had the opportunity to learn a new programming language python.
All applications were developed primarily using Python and on Ubuntu OS architecture.
My first task was to develop health check-ups of geophones which display the variations of
resistance in geophones for the particular day using plotly which uses python and pandas
which could serve the custom needs of geophysicist throughout the world. My second task
was to develop an admin program which gives information about the system that the user is
logged into which could serve the custom needs of users here at ONGC. Through the
following pages of this report I attempt to summarise the projects I have developed over the
course of my winter training.
ABOUT ONGC
Oil and Natural Gas Corporation Limited (ONGC) is an Indian multinational oil and
gas company headquartered in Dehradun, Uttarakhand, India. It is a Public Sector
Undertaking (PSU) of the Government of India, under the administrative control of
the Ministry of Petroleum and Natural Gas. It is India's largest oil and gas exploration and
production company. It produces around 69% of India's crude oil (equivalent to around 30%
of the country's total demand) and around 62% of its natural gas. ONGC was founded on 14
August 1956 by Government of India. Its international subsidiary ONGC Videsh currently
has projects in 17 countries. ONGC has discovered 6 of the 7 commercially producing Indian
Basins, in the last 50 years, adding over 7.1 billion tonnes of In-place Oil & Gas volume of
hydrocarbons in Indian basins. ONGC went offshore in early 70's and discovered a giant oil
field in the form of Bombay High, now known as Mumbai High. This discovery, along with
subsequent discoveries of huge oil and gas fields in Western offshore changed the oil scenario
of the country.
ONGC has many offices throughout India.
Dinesh K Sarraf is the Chairman & Managing Director of Oil and Natural Gas Corporation
Ltd (ONGC), India's most valuable Maharatna public sector enterprise.
• Maharatna ONGC is the largest producer of crude oil and natural gas in India, contributing
around 70 per cent of Indian domestic production. The crude oil is the raw material used by
downstream companies like IOC, BPCL, and HPCL to produce petroleum products like
Petrol, Diesel, Kerosene, Naphtha, and Cooking Gas-LPG.
• ONGC is India’s Top Energy Company and ranks 20th among global energy majors
(Plants). • ONGC ranks 14th in ‘Oil and Gas operations’ and 220th overall in Forbes Global
2000. Acclaimed for its Corporate Governance practices, Transparency International has
ranked ONGC 26th among the biggest publicly traded global giants.
• It is one of the most valued public enterprise in India, and one of the highest profit-making
and dividend-paying. ONGC has a unique distinction of being a company with in-house
service capabilities in all areas of Exploration and Production of oil & gas and related oil-
field services. Winner of the Best Employer award, a dedicated team of over 33,927
professionals toil round the clock in challenging locations.
• Its wholly-owned subsidiary ONGC Videsh Limited (OVL) is the biggest Indian
multinational in the energy space, participating in 36 oil and gas properties in 17 countries.
ONGC subsidiary Mangalore Refinery and Petrochemicals Limited (MRPL) is a Schedule
‘A’ Miniratna, with a single-location refining capacity of 15 million tons per annum.
• ONGC is ranked as the Top Energy Company in India, Fifth in Asia and 20th globally as per
Platt’s Top 250 Global Energy Rankings, 2016; Maintains place as World's Third ranked E&P
Company in the list.
• Ranked 464 in the Newsweek Green Rankings World's Greenest Companies 2016; Ranked
14th among global Oil and Gas Operations industry in Forbes Global 2000 list, 2016 of the
World's biggest companies for 2016; Ranked 220 in the overall list, 2016 - based on Sales
VRC- VIRTUAL REALITY CENTRE “THIRD EYE CENTRE” AT
VASUNDHARA BHAVAN, ONGC, BANDRA, MUMBAI
Visualization with Virtual Reality (VR) Technology has emerged as a powerful tool in E&P
industry for quick identification of depositional plays, improving efficiencies and reducing
drilling risks.
These are the things that I observed in Vasundhara Bhavan:-
DLP 3 Chip Projectors are used for high-performance, high brightness applications in large
rooms such as lecture halls, digital cinemas and other large audience venues. 3 chip systems
produce stunning images in almost any environment.3 Chip DLP technology is currently
considered the top of the line technology for digital projection.
Workstation
LTO 5 Drive
The plotter is a computer printer for printing vector graphics. In the past, plotters were used
in applications such as computer-aided design, though they have generally been replaced with
wide-format conventional printers. Plotters offered the fastest way to efficiently produce very
large drawings or colour high-resolution vector-based artwork when computer memory was
very expensive and processor power was very limited, and other types of printers had limited
graphic output capabilities.
Multifunction Printers
It is file-level computer data storage connected to a computer network providing data access
to heterogeneous clients. NAS not only operates as a file server, but is specialized for this
task either by its hardware, software, or configuration of those elements. NAS is shared
storage on a local area network. A NAS server is a storage appliance that consists of a high
performance file server that plugs into a LAN.
HP Z800 Workstation delivers the extreme speed and massive expandability that you demand
to tackle your biggest challenges. Whole-system computational power from a workstation
that HP Z800 Workstation Combines ultimate performance with a revolutionary new
industrial design, the HP Z800 Workstation delivers the extreme speed and massive
expandability that is demanded to tackle your biggest challenges. optimizes the way the
processor, memory, graphics, OS, and software technology work together.
Display Systems
The Christie Mirage WU14K-J 3-chip DLP projector offers exceptional image quality and
detail in a compact size.
Multi-Channel Amplifiers
MCA Series Multi-Channel Amplifiers provide eight channels of power amplification. Model
MCA 8050 delivers 50 watts/channel into 4 ohms. Channels may be bridged in pairs for
higher combined wattage. Connections are provided for remote control of channel levels &
muting.
High End Workstations
DATA CENTRES
GEOSIM CENTRE
An Advanced Geological Modelling and Reservoir Simulation Centre (GeoSim) with an aim
to consolidate and integrate MH Asset computing resources for G&G Applications,
Modelling, Reservoir Simulations and to meet the ever increasing data size and computing
requirements. The Centre is equipped with latest and advanced Hardware-Software
(Geological Modelling and Reservoir Simulation) along with high speed LAN. This Centre is
equipped with the latest and state-of-the art technologies viz Dell PowerEdge ML630 Blade
servers, Dell PowerEdge R360 Rack Server, NetApp FAS8060 Network Attached Storage
(NAS), Dell ML6020 Tape Library, Latest Net Vault Backup Software , etc. Geological and
Geophysical (G&G) Applications runs on the server. The data is kept at NAS. Using Backup
software – Net Vault, NAS Backup is taken in LT06 Magnetic Tapes.
Operating System Installation
Firstly, we were told about various operating systems and then guided to install Ubuntu
16.04(LTS) operating system. We installed Ubuntu alongside windows on one our system
given.
1. The first thing you need to take care is to create a free space on the computer hard disk in
case the system is installed on a single partition.
Login to your Windows machine with an administrative account and right click on the Start
Menu -> Command Prompt (Admin) in order to enter Windows Command Line.
5. After the boot media finishes loading into RAM you will end-up with a completely
functional Ubuntu system running in live-mode.
On the Launcher hit on the second icon from top, Install Ubuntu 16.04 LTS, and the installer
utility will start. Choose the language you wish to perform the installation and click
on Continue button to proceed further.
Select Ubuntu 16.04 Installation Language
6. Next, leave both options from Preparing to Install Ubuntu unchecked and hit
on Continue button again.
Preparing Ubuntu 16.04 Installation
7. Now it’s time to select an Installation Type. You can choose to Install
Ubuntu alongside Windows Boot Manager, option that will automatically take care of all the
partition steps.
Use this option if you don’t require personalized partition scheme. In case you want a custom
partition layout, check the something else option and hit on Continue button to proceed
further.
The option Erase disk and install Ubuntu should be avoided on dual-boot because is
potentially dangerous and will wipe out your disk.
Select Ubuntu 16.04 Installation Type
8. On this step we’ll create our custom partition layout for Ubuntu 16.04. On this guide will
recommend that you create two partitions, one for root and the other for home accounts data
and no partition for swap (use a swap partition only if you have limited RAM resources or
you use a fast SSD).
We have to create the first partition, the root partition, select the free space (the shrink space
from Windows created earlier) and hit on the + icon below. On partition settings use the
following configurations and hit OK to apply changes:
Size = at least 20000 MB
Type for the new partition = Primary
Location for the new partition = Beginning
Use as = EXT4 journaling file system
Mount point = /
Create Ubuntu 16.04 Partitions
9. When finished, hit the Install Now button in order to apply changes to disk and start the
installation process.
A pop-up window should appear to inform you about swap space. Ignore the alert by pressing
on Continue button.
Next a new pop-up window will ask you if you agree with committing changes to disk.
Hit Continue to write changes to disk and the installation process will now start.
Confirm Partition Changes
11. Next, select your keyboard layout and click on Continue button.
Select Keyboard Layout
12. Pick up a username and password for your administrative sudo account, enter a
descriptive name for your computer and hit Continue to finalize the installation.
This are all the settings required for customizing Ubuntu 16.04 installation. From here on the
installation process will run automatically until it reaches the end.
Create User Account for Ubuntu 16.04
13. After the installation process reaches its end hit on Restart Now button in order to
complete the installation.
The machine will reboot into the Grub menu, where for ten seconds, you will be presented to
choose what OS you wish to use further: Ubuntu 16.04 or Microsoft Windows.
Ubuntu is designated as default OS to boot from. Thus, just press Enter key or wait for
those 10 seconds timeout to drain.
Ubuntu 16.04 Installation Completed
Grub Menu Select Ubuntu or Windows to Boot
14. After Ubuntu finishes loading, login with the credentials created during the installation
process and enjoy it. Ubuntu 16.04 provides NTFS file system support automatically so you
can access the files from Windows partitions just by clicking on the Windows volume.
That’s it! In case you need to switch back to Windows, just reboot the computer and
select Windows from the Grub menu.
Linux Commands
Basic Commands
1. pwd — When you first open the terminal, you are in the home directory of your user. To
know which directory you are in, you can use the “pwd” command. It gives us the absolute
path, which means the path that starts from the root. The root is the base of the Linux file
system. It is denoted by a forward slash( / ). The user directory is usually something like
"/home/username".
2. ls — Use the "Is" command to know what files are in the directory you are in. You can see
all the hidden files by using the command “ls -a”.
3. cd — Use the "cd" command to go to a directory. For example, if you are in the home
folder, and you want to go to the downloads folder, then you can type in “cd Downloads”.
Remember, this command is case sensitive, and you have to type in the name of the folder
exactly as it is. But there is a problem with these commands. Imagine you have a folder
named “Raspberry Pi”. In this case, when you type in “cd Raspberry Pi”, the shell will take
the second argument of the command as a different one, so you will get an error saying that
the directory does not exist. Here, you can use a backward slash. That is, you can use “cd
Raspberry\ Pi” in this case. Spaces are denoted like this: If you just type “cd”and press
enter, it takes you to the home directory. To go back from a folder to the folder before that,
you can type “cd ..” . The two dots represent back.
4. mkdir & rmdir — Use the mkdir command when you need to create a folder or a
directory. For example, if you want to make a directory called “DIY”, then you can type
“mkdir DIY”. Remember, as told before, if you want to create a directory named “DIY
Hacking”, then you can type “mkdir DIY\ Hacking”. Use rmdir to delete a directory.
But rmdir can only be used to delete an emptydirectory. To delete a directory containing
files, use rm.
6. touch — The touch command is used to create a file. It can be anything, from an empty txt
file to an empty zip file. For example, “touch new.txt”.
7. man & --help — To know more about a command and how to use it, use
the man command. It shows the manual pages of the command. For example, “man cd”
shows the manual pages of the cd command. Typing in the command name and the argument
helps it show which ways the command can be used (e.g., cd –help).
8. cp — Use the cp command to copy files through the command line. It takes two
arguments: The first is the location of the file to be copied, the second is where to copy.
9. mv — Use the mv command to move files through the command line. We can also use
the mv command to rename a file. For example, if we want to rename the
file “text” to “new”, we can use “mv text new”. It takes the two arguments, just like
the cp command.
10. locate — The locate command is used to locate a file in a Linux system, just like the
search command in Windows. This command is useful when you don't know where a file is
saved or the actual name of the file. Using the -i argument with the command helps to ignore
the case (it doesn't matter if it is uppercase or lowercase). So, if you want a file that has the
word “hello”, it gives the list of all the files in your Linux system containing the word "hello"
when you type in “locate -i hello”. If you remember two words, you can separate them using
an asterisk (*). For example, to locate a file containing the words "hello" and "this", you can
use the command “locate -i *hello*this”.
Intermediate Commands
1. echo — The "echo" command helps us move some data, usually text into a file. For
example, if you want to create a new text file or add to an already made text file, you just
need to type in, “echo hello, my name is alok >> new.txt”. You do not need to separate the
spaces by using the backward slash here, because we put in two triangular brackets when we
finish what we need to write.
2. cat — Use the cat command to display the contents of a file. It is usually used to easily
view programs.
3. nano, vi, jed — nano and vi are already installed text editors in the Linux command line.
The nano command is a good text editor that denotes keywords with color and can recognize
most languages. And vi is simpler than nano. You can create a new file or modify a file using
this editor. For example, if you need to make a new file named "check.txt", you can create it
by using the command “nano check.txt”. You can save your files after editing by using the
sequence Ctrl+X, then Y (or N for no). In my experience, using nano for HTML editing
doesn't seem as good, because of its color, so I recommend jed text editor. We will come to
installing packages soon.
4. sudo — A widely used command in the Linux command line, sudo stands for "SuperUser
Do". So, if you want any command to be done with administrative or root privileges, you can
use the sudo command. For example, if you want to edit a file like viz. alsa-base.conf, which
needs root permissions, you can use the command – sudo nano alsa-base.conf. You can enter
the root command line using the command “sudo bash”, then type in your user password.
You can also use the command “su” to do this, but you need to set a root password before
that. For that, you can use the command “sudo passwd”(not misspelled, it is passwd). Then
type in the new root password.
5. df — Use the df command to see the available disk space in each of the partitions in your
system. You can just type in df in the command line and you can see each mounted partition
and their used/available space in % and in KBs. If you want it shown in megabytes, you can
use the command “df -m”.
6. du — Use du to know the disk usage of a file in your system. If you want to know the disk
usage for a particular folder or file in Linux, you can type in the command df and the name of
the folder or file. For example, if you want to know the disk space used by the documents
folder in Linux, you can use the command “du Documents”. You can also use the
command “ls -lah” to view the file sizes of all the files in a folder.
7. tar — Use tar to work with tarballs (or files compressed in a tarball archive) in the Linux
command line. It has a long list of uses. It can be used to compress and uncompress different
types of tar archives like .tar, .tar.gz, .tar.bz2,etc. It works on the basis of the arguments
given to it. For example, "tar -cvf" for creating a .tar archive, -xvf to untar a tar archive, -
tvf to list the contents of the archive, etc. Since it is a wide topic, here are some examples of
tar commands.
8. zip, unzip — Use zip to compress files into a zip archive, and unzip to extract files from a
zip archive.
9. uname — Use uname to show the information about the system your Linux distro is
running. Using the command “uname -a” prints most of the information about the system.
This prints the kernel release date, version, processor type, etc.
10. apt-get — Use apt to work with packages in the Linux command line. Use apt-get to
install packages. This requires root privileges, so use the sudocommand with it. For example,
if you want to install the text editor jed (as I mentioned earlier), we can type in the command
“sudo apt-get install jed”. Similarly, any packages can be installed like this. It is good to
update your repository each time you try to install a new package. You can do that by
typing “sudo apt-get update”. You can upgrade the system by typing “sudo apt-get
upgrade”. We can also upgrade the distro by typing “sudo apt-get dist-upgrade”. The
command “apt-cache search” is used to search for a package. If you want to search for one,
you can type in “apt-cache search jed”(this doesn't require root).
11. chmod — Use chmod to make a file executable and to change the permissions granted to
it in Linux. Imagine you have a python code named numbers.py in your computer. You'll
need to run “python numbers.py” every time you need to run it. Instead of that, when you
make it executable, you'll just need to run “numbers.py” in the terminal to run the file. To
make a file executable, you can use the command “chmod +x numbers.py” in this case. You
can use “chmod 755 numbers.py” to give it root permissions or “sudo chmod +x
numbers.py” for root executable. Here is some more information about
the chmod command.
12. hostname — Use hostname to know your name in your host or network. Basically, it
displays your hostname and IP address. Just typing “hostname”gives the output. Typing in
“hostname -I” gives you your IP address in your network.
13. ping — Use ping to check your connection to a server. Wikipedia says, "Ping is a
computer network administration software utility used to test the reachability of a host on an
Internet Protocol (IP) network". Simply, when you type in, for example, “ping google.com”,
it checks if it can connect to the server and come back. It measures this round-trip time and
gives you the details about it. The use of this command for simple users like us is to check
your internet connection. If it pings the Google server (in this case), you can confirm that
your internet connection is active!
1. Download Python 2.7.10 source code from python using wget command given below.
$ cd ~/Downloads
$ wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
4 . Go to Python-2.7.10 folder, configure and build python source code with make altinstall
command as given below.
$ cd ~/Downloads/Python-2.7.10/
$ sudo ./configure
Build process takes some time. Once this step is successful, python 2.7.10 installation is
successful.
$ whereis python2.7
$ python2.7 –version
Python
I used the Python version 2.7.11.
Python is an easy to learn, powerful programming language. It has efficient high-level data
structures and a simple but effective approach to object-oriented programming. Python’s
elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal
language for scripting and rapid application development in many areas on most platforms.
The Python interpreter is easily extended with new functions and data types implemented in
C or C++ (or other languages callable from C). Python is also suitable as an extension
language for customizable applications.
Some Basic uses of Python that I used in my project
2. Defining Functions
The keyword def introduces a function definition. It must be followed by the function name
and the parenthesized list of formal parameters. The statements that form the body of the
function start at the next line, and must be indented.
3.for Statements
The for statement in Python differs a bit from what you may be used to in C.
Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or
giving the user the ability to define both the iteration step and halting condition (as C),
Python’s for statement iterates over the items of any sequence (a list or a string), in the order
that they appear in the sequence.
Pythons Data Science library
INTRODUCTION:
A geophone is a ground motion transducer that has been used by geophysicists and
seismologists to convert ground movement into voltage. Any deviation in this
measured voltage from the base line is regarded as seismic response, which is used
for analyzing the earth’s structure.
Resonance frequency is the key factor in a geophone, and it has to be low for the
measurement of low-frequency signals. On the other hand, geophone must exhibit
high bandwidth to measure high-frequency signals as well. However, most of the
currently available geophones include mechanical springs that decrease the
performance of the device.
Feeding back the output of geophone can vary the geophone’s sensitivity with
respect to its frequency, and as a result low frequency signals are amplified. The
resolution of geophone can be enhanced by controlling the position of proof mass.
Working Principle
A typical geophone consists of a mass suspended by means of mechanical springs.
The geophone housing and the suspended mass start moving with the application of
a velocity at frequencies lesser than the resonance frequency.
The mass will remain stationary for frequencies greater than the resonance
frequency. The movement of mass is based on either magnets or coils. The
response of a coil/magnet geophone is proportional to the ground velocity.
Applications
Geophones are used for several industrial applications for vibration isolation
purposes and absolute velocity sensing to achieve a high level of accuracy and
precision. Geophone technology is employed to measure absolute velocity for
lithographic and high-level inspection applications to determine payload disturbances
caused by moving parts and other external disturbances.
They are also used to position and control a complex lens system. Detection of
leakage in oil and gas fields and earthquake prediction are also other major
applications of geophones.
OBJECTIVES:
The aim of the project is to visualize the resistance of the geophones and
accordingly we can tell the status of the geophones i.e. good or bad.
METHODOLOGY:
Input consists of csv files having resistance of each geophone
along with some other parameters like tilt etc. Each file
represents the data taken for a particular time for a single day.
Files are then cleaned and removed the unwanted columns and
strings.
Processed files are then parsed into Python’s Data Science
Library and then they are plotted using Plotly.
Admin
Authorizations for who is in the groups
Authorizations for users
Users
Can upload, view and download the files
Groups
Authorized the users in the particular group
Using Python's csv module to parse the data
We create empty lists to contain the latitudes and longitudes. Then we use the
with statement to ensure that the file closes properly once it has been read,
even if there are errors in processing the file.
With the data file open, we initialize a csv reader object. The next() function
skips over the header row. Then we loop through each row in the data file,
and pull out the information we want.
USING PYPLOT
import psycopg2
#!/usr/bin/python
import psycopg2
cur = conn.cursor()
cur.execute('''CREATE TABLE COMPANY
(ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL);''')
print "Table created successfully"
conn.commit()
conn.close()
Creating a project
If this is your first time using Django, you’ll have to take care of some initial setup. Namely,
you’ll need to auto-generate some code that establishes a Django project – a collection of
settings for an instance of Django, including database configuration, Django-specific options
and application-specific settings.
From the command line, cd into a directory where you’d like to store your code, then run the
following command:
$ django-admin startproject mysite
This will create a mysite directory in your current directory.
Let’s look at what startproject created:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
These files are:
The outer mysite/ root directory is just a container for your project. Its name doesn’t matter
to Django; you can rename it to anything you like.
manage.py: A command-line utility that lets you interact with this Django project in various
ways. You can read all the details about manage.py in django-admin and manage.py.
The inner mysite/ directory is the actual Python package for your project. Its name is the
Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).
mysite/__init__.py: An empty file that tells Python that this directory should be considered a
Python package
mysite/settings.py: Settings/configuration for this Django project. Django settings will tell
you all about how settings work.
mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your
Django-powered site.
mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project.
The development server
$ python manage.py runserver
You’ve started the Django development server, a lightweight Web server written purely in
Python.
Awk
AWK is an interpreted programming language designed for text processing and
typically used as a data extraction and reporting tool. It is a standard feature of
most Unix-like operating systems.
The AWK language is a data-driven scripting language consisting of a set of
actions to be taken against streams of textual data – either run directly on files or
used as part of a pipeline – for purposes of extracting or transforming text, such as
producing formatted reports. The language extensively uses the string datatype,
associative arrays (that is, arrays indexed by key strings), and regular expressions.
While AWK has a limited intended application domain and was especially
designed to support one-liner programs, the language is Turing-complete, and
even the early Bell Labs users of AWK often wrote well-structured large AWK
programs.
AWK was created at Bell Labs in the 1970s,and its name is derived from the
surnames of its authors – Alfred Aho, Peter Weinberger, and Brian Kernighan.
AWK is a language for processing text files. A file is treated as a sequence of
records, and by default each line is a record. Each line is broken up into a
sequence of fields, so we can think of the first word in a line as the first field, the
second word as the second field, and so on. An AWK program is a sequence of
pattern-action statements. AWK reads the input a line at a time. A line is scanned
for each pattern in the program, and for each pattern that matches, the associated
action is executed.
An AWK program is a series of pattern action pairs,
written as:
condition { action }
where condition is typically an expression and action is a series of commands. The
input is split into records, where by default records are separated by newline
characters so that the input is split into lines. The program tests each record
against each of the conditions in turn, and executes the action for each expression
that is true. Either the condition or the action may be omitted. The condition
defaults to matching every record. The default action is to print the record.
AWK commands
AWK commands are the statements that are substituted for action in the examples
above. AWK commands can include function calls, variable assignments,
calculations, or any combination thereof. AWK contains built-in support for many
functions; many more are provided by the various flavors of AWK. Also, some
flavors support the inclusion of dynamically linked libraries, which can also
provide more functions.
The print command
The print command is used to output text. The output text is always terminated
with a predefined string called the output record separator (ORS) whose default
value is a newline. The simplest form of this command is:
print
This displays the contents of the current record. In AWK, records are broken down
into fields, and these can be displayed separately:
print $1
Displays the first field of the current record
print $1, $3
Displays the first and third fields of the current record, separated by a predefined
string called the output field separator (OFS) whose default value is a single space
character.
Sample applications
BEGIN { print "Hello, world!" }
Print lines longer than 80 characters
length($0) > 80
Print a count of words
{
w += NF
c += length + 1
}
END { print NR, w, c }