Professional Documents
Culture Documents
Example:
$ cat file
hello world
m_dump<dml_file_name><input_file_name> -decompress
or
touch –a --- updates the current timestamp for a file(tried but not happening)
touch –c --- if file available, updates the timestamp but does not create a file, if file doesn’t
already exists
Alternative Way:
is equal to: eq
is not equal to: ne
is greater than: gt
is less than: lt
is greater than or equal to: ge
is less than or equal to: le
unset_project_env
prstat -a (top command)
du -gh, df -gh
sudo -u <user_id>ksh
Operators
-b file
-c file
-d file
-e file
-f file
-g file
true if the setgid attribute of the file is on under UNIX (or the system attribute on Windows systems)
-h file
-k file
true if the save text attribute of the file is on under UNIX (or the archive attribute on Windows
systems)
-L file
-n string
-p file
-r file
true if the file is readable
-s file
-t fd
true if the numeric file descriptor fd is open and associated with a terminal
-u file
true if the setuid attribute of the file is on under UNIX (or the hidden attribute on Windows systems)
-w file
-x file
true if the file is executable. If the specified file does not exist, test checks each extension in the
PATHEXT environment variable (in the order listed) to see if a file exists with the specified name plus
that extension. If such a file does exist and it is executable, -x returns true.
-z string
All existing files are considered to be newer than a nonexistent file. In turn, no nonexistent file is
newer than any existing file. Two nonexistent files are considered the same age.
Note:
A nonexistent file is considered to be older than any existing file. In turn, no existing file is older than
a nonexistent file. Two nonexistent files are considered the same age.
true if file1 has the same device and i-node number as file2
The following operators handle string comparisons for the test and [ commands:
string
string1 = string2
string1 != string2
string != pattern
expr1 -a expr2 (test and [ commands) expr1 && expr2 ([[ command)
! expr
( expr )
• parenthesized expressions
• unary operators
• comparison operators
• logical AND
• logical OR
EXAMPLES
The following command reports on whether the first positional parameter contains a directory or a
file:
if [ -f $1 ]
then
echo $1 is a file
elif [ -d $1 ]
then
echo $1 is a directory
else
fi
http://www.folkstalk.com/2012/01/sed-command-in-unix-examples.html
https://www.tecmint.com/linux-sed-command-tips-tricks/
tr command examples:
http://www.thegeekstuff.com/2012/12/linux-tr-command/
grep command"
https://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/
https://www.thegeekstuff.com/2011/01/regular-expressions-in-grep-command/
https://www.linuxnix.com/awk-scripting-10-begin-and-end-block-examples/
This will print the squares of first numbers from 1 to 5. The output of the command is
print the sum of the columns with sum value greater than 1000.
index(string,search)
length(string)
split(string,array,separator)
substr(string,position)
substr(string,position,max)
tolower(string)
toupper(string)
awk '{
split($2,arr,",");
if(arr[3] == "UNIX")
print $0
} ' file.txt
BEGIN { x=0 }
/^$/ { x=x+1 }
END { print "I found " x " blank lines. :)" }
https://www.ibm.com/developerworks/library/l-awk1/index.html
https://www.funtoo.org/Awk_by_Example,_Part_1
http://www.folkstalk.com/2011/11/unix-interview-questions-on-awk-command.html
interview questions:
https://career.guru99.com/shell-scripting-interview-questions/
seen is an associative-array that Awk will pass every line of the file to. If a line isn't
in the array then seen[$0] will evaluate to false. The ! is a logical NOT operator
and will invert the false to true. Awk will print the lines where the expression
evaluates to true. The ++ increments seen so that seen[$0] == 1 after the first time
a line is found and then seen[$0] == 2, and so on.
Awk evaluates everything but 0 and "" (empty string) to true. If a duplicate line is
placed in seenthen !seen[$0] will evaluate to false and the line will not be written to
the output.