Unit-3 Group (Unix)
Unit-3 Group (Unix)
Important Points:
Groups command prints the names of the primary and any
supplementary groups for each given username, or the current
process if no names are given.
If more than one name is given, the name of each user is printed
before the list of that user’s groups and the username is separated
from the group list by a colon.
https://www.geeksforgeeks.org/grep-command-in-unixlinux/
Here,
[options]: These are command-line flags that modify the behavior
of grep.
[pattern]: This is the regular expression you want to search for.
[file]: This is the name of the file(s) you want to search within. You can
specify multiple files for simultaneous searching.
Output:
Comparison Operators
You can compare two variables in shell scripting. We do these
comparisons to make decisions, we will see how to do that later in this
article, but before that, here is a list of some comparison operators.
Integer comparison
Operator Description
-eq is equal to
Operator Description
== is equal to
!= is not equal to
We add a \ before < and > because they need to be escaped when typed
in the [ ] construct. Now, let’s see where these are used.
Conditional statements
Conditional statements are used to execute a block of code only when
certain conditions are met. Shell scripts support the use of conditional
statements. We use comparison operators to check the conditions. Let’s
see a few conditional statements.
If statement
Group Command:-
Users can be listed in different groups. Group allow us to set permission on the
group level instead of setting the permission on individual level.
Every Linux distribution have a graphical tool to manage groups. Groups can be
managed by graphical tools, command line tools and by vi or vigr depending upon
the user's experience
groupadd
Syntax:
1. groupadd <groupName>
Example:
1. groupadd php
2. groupadd java
3. groupadd android
4. groupadd spring
Group File
The /etc/group file defines the group membership. A user can be a member of more
than one group.
Syntax:
1. /etc/group
Groups
The group command tells about the group where current user belongs to.
Syntax:
1. groups
Awk commands:-
Awk is a scripting language used for manipulating data and generating
reports. The awk command programming language requires no compiling
and allows the user to use variables, numeric functions, string functions, and
logical operators.
Awk is a utility that enables a programmer to write tiny but effective programs
in the form of statements that define text patterns that are to be searched for
in each line of a document and the action that is to be taken when a match is
found within a line. Awk is mostly used for pattern scanning and processing.
It searches one or more files to see if they contain lines that matches with
the specified patterns and then perform the associated actions.
AWK Operations:
(a) Scans a file line by line
(b) Splits each input line into fields
(c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines
2. Useful For:
(a) Transform data files
(b) Produce formatted reports
3. Programming Constructs:
(a) Format output lines
(b) Arithmetic and string operations
(c) Conditionals and loops
Syntax:
awk options 'selection _criteria {action }' input-file > output-
file
Sample Commands
Example:
Consider the following text file as the input file for all cases below:
$cat > employee.txt
ajay manager account 45000
sunil clerk account 25000
varun manager sales 50000
amit manager account 47000
tarun peon sales 15000
deepak clerk sales 23000
sunil peon sales 13000
satvik director purchase 80000
1. Default behavior of Awk: By default Awk prints every line of data from
the specified file.
$ awk '{print}' employee.txt
Output:
ajay manager account 45000
sunil clerk account 25000
varun manager sales 50000
amit manager account 47000
tarun peon sales 15000
deepak clerk sales 23000
sunil peon sales 13000
satvik director purchase 80000
In the above example, no pattern is given. So the actions are applicable to all
the lines. Action print without any argument prints the whole line by default,
so it prints all the lines of the file without failure.