In [1]:
import os
In [2]:
path=!echo $PATH
In [3]:
print path
In [7]:
path[0].split(":")
Out[7]:
In [8]:
print len(path[0].split(":"))
which is the same as the following command in BASH shell:
In [9]:
!echo $PATH|tr ":" " "|wc -w
In [13]:
!locale
In [30]:
!export LANG='en_US.UTF-8'
In [34]:
!locale
the flag -ld of "ls" means "list directory".
In [35]:
!ls -ld /etc/p*
In [36]:
!ls -ld /etc/p* | wc -l
In [37]:
!ls -ld /etc/p????
In [39]:
!ls -ld /etc/p???? | wc -l
In [41]:
!ls -ld /etc/p[aeiou]*
In [42]:
!ls -ld /etc/p[aeiou]* | wc -l
In [45]:
!ls -ld /etc/p[!aeiou]*
In [87]:
!ls -ld /etc/p[^aeiou]*
where [!aeiou] means: not a or e or i or u.
Indeed,in this case, regular expressoin [^aeiou] also works.
In [47]:
!touch d{m,n,o}t
In [49]:
!ls
In [59]:
import re
In [52]:
!wget http://linux.vbird.org/linux_basic/0330regularex/regular_express.txt
In [57]:
!cat -n regular_express.txt
In [56]:
!cat regular_express.txt |wc -l
In [58]:
!grep -n 'the' regular_express.txt
the above BASH command is the same as the following code in Python:
In [102]:
pattern = re.compile('the')
for line in open("regular_express.txt", "r"):
if pattern.search(line) is not None:
print line
In [66]:
!grep -nv 'the' regular_express.txt
In [67]:
!grep -ni 'the' regular_express.txt
In [68]:
!grep -n 'air' regular_express.txt
In [86]:
!grep -ni 't[ae]st' regular_express.txt
In [90]:
!grep -n 't[ae]st' regular_express.txt
In [94]:
!grep -n '[^g]oo' regular_express.txt
In [106]:
!grep -n '[[:digit:]]' regular_express.txt
In [105]:
!grep -n '[[:lower:]]' regular_express.txt
In [107]:
!grep -n '^[^A-Za-z]' regular_express.txt
In [108]:
!grep -n '!$' regular_express.txt
In [109]:
!grep -n '.$' regular_express.txt
In [110]:
!grep -n 's.c' regular_express.txt
In [111]:
!grep -n 's[a-zA-Z]c' regular_express.txt
In [112]:
!grep -n 'oo' regular_express.txt
In [113]:
!grep -n 'ooo*' regular_express.txt
In [ ]:
!grep -n 'g*g' regular_express.txt
using 'ooo*' will lead to the same result as using 'oo'
In [115]:
!grep -nE 'goo+g' regular_express.txt
In [4]:
!ps -el |grep -E '^[0-9]+ R'
-E flag has to be added if one want to use expressions such as + or |.
In [119]:
!dpkg -L iproute2 | grep -E '/bin|/sbin'
In [120]:
!dpkg -L iproute2 | grep -E '/bin|/sbin' | wc -l
In [121]:
!dpkg -L iproute2 | grep -E '/s?bin' | wc -l
In [77]:
f=open("regular_express.txt", "r")
file=f.read()
In [81]:
print repr(file)
In [83]:
for line in open("regular_express.txt", "r"):
print line
In [142]:
os.mkdir("tmp")
In [144]:
os.listdir(os.getcwd())
Out[144]:
In [145]:
ls
In [147]:
os.removedirs("tmp")
In [148]:
os.listdir(".")
Out[148]:
In [141]:
for root,dirs,files in os.walk(os.getcwd()):
print root,dirs,files
print
In [139]:
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
print os.path.join(root,file)
In [140]:
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
if file.endswith('.txt'):
print file
In [129]:
!whereis regex
In [134]:
!find / -name 'ifconfig'
In [151]:
!find -type f -user chweng -name '*.txt'
In [158]:
!find -type d -user chweng -name '0*'
In [162]:
!sudo fdisk -l | grep -nE "^Disk /dev/[hs]d"
In [ ]:
sudo find /etc -type f | wc -l
In [ ]:
du -hl /etc/
chweng@chweng-VirtualBox:~$ jobs
[1]+ Running sleep 100 &
chweng@chweng-VirtualBox:~$ fg 1 # move process 1 to the foreground
sleep 100
then, we can press ctrl+z, which will move the process to the background and pause it.
then, type "bg 1" in order to start it again in the background
flags:
-e:all processes
-l:state
-f: also print UID(user ID) and PPID(parent process ID)
In [3]:
!ps -el
RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.
SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.
use "top -o RES" to sort by resident size(RES)
The following cell is the content of the script testPS.sh:
#!/bin/bash
ps -f
#read
Now, we execute it:
chweng@chweng-VirtualBox:~/code/exercises$ ./testPS.sh
UID PID PPID C STIME TTY TIME CMD
chweng 9960 2374 0 16:26 pts/31 00:00:00 bash
chweng 9974 9960 0 16:26 pts/31 00:00:00 /bin/bash ./testPS.sh
chweng 9975 9974 0 16:26 pts/31 00:00:00 ps -f
chweng@chweng-VirtualBox:~/code/exercises$ source testPS.sh
UID PID PPID C STIME TTY TIME CMD
chweng 9960 2374 0 16:26 pts/31 00:00:00 bash
chweng 9980 9960 0 16:26 pts/31 00:00:00 ps -f
chweng@chweng-VirtualBox:~$ var1=1111
chweng@chweng-VirtualBox:~$ var2=3333
chweng@chweng-VirtualBox:~$ echo "${var1}222"
1111222
chweng@chweng-VirtualBox:~$ set | grep "var1"
var1=1111
chweng@chweng-VirtualBox:~$ set | grep "var2"
var2=3333
chweng@chweng-VirtualBox:$ export var1
chweng@chweng-VirtualBox:$ bash
chweng@chweng-VirtualBox:$ echo $var1
1111
chweng@chweng-VirtualBox:$ echo $var2
In [11]:
%%bash
var=12345
echo "The length of var1=$var is ${#var}."
In [24]:
%%bash
set $(eval du -sh ~$user);dir_sz=$1
echo "$1,$2"
echo "${dir_sz}"
echo ""
set $(eval df -h|grep " /$");fs_sz=$2
echo "$1,$2"
echo "${fs_sz}"
In [21]:
%%bash
set $(eval du -sh ~$user);dir_sz=$1
set $(eval df -h|grep " /$");fs_sz=$2
echo "Size of my home directory is ${dir_sz}."
echo "Size of my file system size is ${fs_sz}."
In [27]:
%%bash
:
echo "exit status=$?"
In [28]:
%%bash
ls /dhuoewyr242q
echo "exit status=$?"
In [29]:
%%bash
true
echo "exit status=$?"
In [30]:
%%bash
false
echo "exit status=$?"
In [34]:
%%bash
value=123
test $value=="123"
echo "exit status=$?"
echo""
test $value=="456"
echo "exit status=$?"
The above result is wrong. it's necessary to wrap == with SPACES, as the follows:
In [37]:
%%bash
value=123
test $value == "123"
echo "exit status=$?"
echo""
test $value == "456"
echo "exit status=$?"
In [40]:
%%bash
help [
In [41]:
%%bash
value=123
[ $value == "123" ]
echo "exit status=$?"
echo""
[ $value == "456" ]
echo "exit status=$?"
In [46]:
%%bash
/usr/bin/[ 0 == 1 ]
echo "exit status=$?"
use the advanced-test:[[]]
to compare different integer strings in different forms (it could be that one in decimal and another in octal format)
In [47]:
%%bash
#!/bin/bash
# using [ and [[
file=/etc/passwd
if [[ -e $file ]]
then
echo "Password file exists."
fi
# [[ Octal and hexadecimal evaluation ]]
# Thank you, Moritz Gronbach, for pointing this out.
decimal=15
octal=017 # = 15 (decimal)
hex=0x0f # = 15 (decimal)
if [ "$decimal" -eq "$octal" ]
then
echo "$decimal equals $octal"
else
echo "$decimal is not equal to $octal" # 15 is not equal to 017
fi # Doesn't evaluate within [ single brackets ]!
if [[ "$decimal" -eq "$octal" ]]
then
echo "$decimal equals $octal" # 15 equals 017
else
echo "$decimal is not equal to $octal"
fi # Evaluates within [[ double brackets ]]!
if [[ "$decimal" -eq "$hex" ]]
then
echo "$decimal equals $hex" # 15 equals 0x0f
else
echo "$decimal is not equal to $hex"
fi # [[ $hexadecimal ]] also evaluates!
In [48]:
!mkdir /home/chweng/a
In [49]:
!touch /home/chweng/a/123.txt
In [58]:
%%bash
#!/bin/bash
# using file test operator
DEST="~/b"
SRC="~/a"
# Make sure backup dir exits
if [ ! -d $DEST ]
then
mkdir -p $DEST
fi
# If source directory does not exits, die...
if [ ! -d $SRC ]
then
echo "$SRC directory not found. Cannot make backup to $DEST"
exit 1
fi
# Okay, dump backup using tar
echo "Backup directory $DEST..."
echo "Source directory $SRC..."
/bin/tar -Jcf $DEST/backup.tar.xz $SRC 2>/dev/null
# Find out if backup failed or not
if [ $? -eq 0 ]
then
echo "Backup done!"
else
echo "Backup failed"
fi
In [81]:
%%bash
i=5
if [ $i -ge 0 ];then echo "$i >= 0";fi
alternatively, one can write it like this (with the help of )
In [83]:
%%bash
i=5
if (($i >= 0));then echo "$i >= 0";fi
In [77]:
%%bash
i=5
if [ $i >= 0 ];then echo "$i >= 0";fi
In [75]:
%%bash
i=05
if [ $i -ge 0 ];then echo "$i >= 0";fi
In [74]:
%%bash
echo $((7**2))
In [75]:
%%bash
echo $((7%3))
In [86]:
%%bash
#!/bin/bash
# calculate the available % of disk space
echo "Current Mount Points:"
mount | grep -E 'ext[234]|xfs' | cut -f 3 -d ' '
#read -p "Enter a Mount Point: " mntpnt
mntpnt="/home"
sizekb=$(df $mntpnt | tail -1 | tr -s ' ' | cut -f 2 -d ' ')
availkb=$(df $mntpnt | tail -1 | tr -s ' ' | cut -f 4 -d ' ')
availpct=$(echo "scale=4; $availkb/$sizekb * 100" | bc)
printf "There is %5.2f%% available in %s\n" $availpct $mntpnt
exit 0
Another code which do exactly the same thing:
In [87]:
%%bash
#!/bin/bash
# calculate the available % of disk space
echo "Current Mount Points:"
mount | egrep 'ext[234]|xfs' | cut -f 3 -d ' ' # -f: field; -d:delimiter
#read -p "Enter a Mount Point: " mntpnt
mntpnt="/home"
df_out="$(df $mntpnt | tail -1)"
set $df_out
availpct=$(echo "scale=4; ${4}/${2} * 100" | bc)
printf "There is %5.2f%% available in %s\n" $availpct $mntpnt
exit 0
In [93]:
%%bash
#!/bin/bash
# shift left is double, shift right is half
declare -i number
#read -p "Enter a number: " number
number=-4
echo " Double $number is: $((number << 1))"
echo " Half of $number is: $((number >> 1))"
exit 0
therefore, it is arithmatic shift in the above script.
local variables can be declared as readonly
In [1]:
%%bash
#!/bin/bash
# declare constants variables
readonly DATA=/home/sales/data/feb09.dat
echo $DATA
echo
DATA=/tmp/foo
# Error ... readonly variable
echo $DATA
exit 0
In [5]:
%%bash
#!/bin/bash
# Testing ranges of characters.
Keypress=5
#echo; echo "Hit a key, then hit return."
#read Keypress
case "$Keypress" in
[[:lower:]] ) echo "Lowercase letter";;
[[:upper:]] ) echo "Uppercase letter";;
[0-9] ) echo "Digit";;
* ) echo "Punctuation, whitespace, or other";;
esac # Allows ranges of characters in [square brackets],
#+ or POSIX ranges in [[double square brackets.
In [7]:
%%bash
#!/bin/bash
# menu case
echo -n "
Menu of available commands:
=================================
1. full directory listing
2. display current directory name
3. display the date
q. quit
=================================
Select a number from the list: "
#read answer
answer=2
case "$answer" in
q*|exit|bye ) echo "Quitting!" ; exit ;;
1) echo "The contents of the current directory:"
ls -al ;;
2) echo "The name of the current directory is $(pwd)" ;;
3) echo -n "The current date is: "
date +%m/%d/%Y ;;
*) echo "Only choices 1, 2, 3 or q are valid" ;;
esac
exit
in the above example, \$(pwd) can be replaced by $PWD if the env variable PWD exists
In [ ]:
for planet in "Mercury 36" "Venus 67" "Earth 93" "Mars 142" "Jupiter 483"
In [12]:
%%bash
#!/bin/bash
# Planets revisited.
# Associate the name of each planet with its distance from the sun.
for planet in "Mercury 36" "Venus 67" "Earth 93" "Mars 142" "Jupiter 483"
do
set -- $planet # Parses variable "planet"
#+ and sets positional parameters.
# The "--" prevents nasty surprises if $planet is null or
#+ begins with a dash.
# May need to save original positional parameters,
#+ since they get overwritten.
# One way of doing this is to use an array,
# original_params=("$@")
echo "$1 $2,000,000 miles from the sun"
#-------two tabs---concatenate zeroes onto parameter $2
done
# (Thanks, S.C., for additional clarification.)
exit 0
In [19]:
%%bash
#!/bin/bash
#echo $1
#file=$1
cd /home/chweng/code/exercises/
file="hello.sh"
if [ -f $file ]
then
echo "the file $file exists"
fi
for((j=1;j<=5;j++))
do
echo $j, "Hello World"
done
In [7]:
%%bash
#!/bin/bash
#echo $1
#file=$1
cd /home/chweng/code/exercises/
file="hello.sh"
if [[ -f $file && true ]]
then
echo "the file $file exists"
fi
for((j=1;j<=5;j++))
do
echo $j, "Hello World"
done
In [23]:
%%bash
#!/bin/bash
# increment number
# set n to 1
n=1
# continue until $n equals 5
while [ $n -le 5 ]
do
echo "Welcome $n times."
n=$(( n+1 )) # increments $n
done
In [32]:
%%bash
#!/bin/bash
# increment number
# set n to 1
n=1
# continue until $n equals 5
while (( n <= 5 ))
do
echo "Welcome $n times."
(( n++ )) # increments $n
done
In [40]:
%%bash
#!/bin/bash
# while can read data
ls -al | while read perms links owner group size mon day time file
do
[[ "$perms" != "total" && $size -gt 100 ]] && echo "$file $size"
done
exit
In [42]:
%%bash
#!/bin/bash
# break, continue usage
LIMIT=19 # Upper limit
echo
echo "Printing Numbers 1 through 20 (but not 3 and 11)."
a=0
while (( a <= LIMIT))
do
((a++))
if [[ "$a" -eq 3 || "$a" -eq 11 ]] # Excludes 3 and 11.
then
continue # Skip rest of this particular loop iteration.
fi
echo -n "$a " # This will not execute for 3 and 11.
done
# Exercise:
# Why does the loop print up to 20?
echo; echo
echo Printing Numbers 1 through 20, but something happens after 2.
##################################################################
# Same loop, but substituting 'break' for 'continue'.
a=0
while [ "$a" -le "$LIMIT" ]
do
a=$(($a+1))
if [ "$a" -gt 2 ]
then
break # Skip entire rest of loop.
fi
echo -n "$a "
done
exit 0
In [43]:
%%bash
#!/bin/bash
# The "continue N" command, continuing at the Nth level loop.
for outer in I II III IV V # outer loop
do
echo; echo -n "Group $outer: "
# --------------------------------------------------------------------
for inner in 1 2 3 4 5 6 7 8 9 10 # inner loop
do
if [[ "$inner" -eq 7 && "$outer" = "III" ]]
then
continue 2 # Continue at loop on 2nd level, that is "outer loop".
# Replace above line with a simple "continue"
# to see normal loop behavior.
fi
echo -n "$inner " # 7 8 9 10 will not echo on "Group III."
done
# --------------------------------------------------------------------
done
echo; echo
exit 0
In [19]:
%%bash
#!/bin/bash
# The "continue N" command, continuing at the Nth level loop.
for outer in I II III IV V # outer loop
do
echo; echo -n "Group $outer: "
# --------------------------------------------------------------------
for inner in 1 2 3 4 5 6 7 8 9 10 # inner loop
do
if [[ "$inner" -eq 7 && "$outer" = "III" ]]
then
break 2 # Continue at loop on 2nd level, that is "outer loop".
# Replace above line with a simple "continue"
# to see normal loop behavior.
fi
echo -n "$inner " # 7 8 9 10 will not echo on "Group III."
done
# --------------------------------------------------------------------
done
echo; echo
exit 0
In [47]:
%%bash
#!/bin/bash
# Exercising functions (simple).
JUST_A_SECOND=1
funky ()
{ # This is about as simple as functions get.
echo "This is a funky function."
echo "Now exiting funky function."
} # Function declaration must precede call.
fun ()
{ # A somewhat more complex function.
i=0
REPEATS=5
echo
echo "And now the fun really begins."
echo
sleep $JUST_A_SECOND # Hey, wait a second!
while [ $i -lt $REPEATS ]
do
echo "----------FUNCTIONS---------->"
echo "<------------ARE-------------"
echo "<------------FUN------------>"
echo
((i++))
done
}
# Now, call the functions.
funky
fun
exit $?
chweng@chweng-VirtualBox:~$ env |grep "PWD"
PWD=/home/chweng
chweng@chweng-VirtualBox:~$
chweng@chweng-VirtualBox:~$ cd Desktop/
chweng@chweng-VirtualBox:~/Desktop$ env |grep "PWD"
PWD=/home/chweng/Desktop
OLDPWD=/home/chweng
In [48]:
%%bash
#!/bin/bash
# Global and local variables inside a function.
func ()
{
local loc_var=23 # Declared as local variable.
echo # Uses the 'local' builtin.
echo "\"loc_var\" in function = $loc_var"
global_var=999 # Not declared as local.
# Therefore, defaults to global.
echo "\"global_var\" in function = $global_var"
}
func
# Now, to see if local variable "loc_var" exists outside the function.
echo
echo "\"loc_var\" outside function = $loc_var"
# $loc_var outside function =
# No, $loc_var not visible globally.
echo "\"global_var\" outside function = $global_var"
# $global_var outside function = 999
# $global_var is visible globally.
echo
exit 0
# In contrast to C, a Bash variable declared inside a function
#+ is local ONLY if declared as such.
In [51]:
%%bash
#!/bin/bash
# passing data to function
# DECLARE FUNCTIONS
shifter() # function to demonstrate parameter
# list management in a function
{
echo "$# parameters passed to $0"
while (( $# > 0 ))
do
echo "$*"
shift
done
}
# MAIN
#read -p "Please type a list of five words (then press Return): " varlist
varlist="i my me mine myself"
set $varlist # this creates positional parameters in the parent
shifter $* # call the function and pass argument list
echo "$# parameters in the parent "
echo "Parameters: $*"
exit
In [53]:
%%bash
#!/bin/bash
# Functions and parameters
DEFAULT=default # Default param value.
func2 () {
if [ -z "$1" ] # Is parameter #1 zero length?
then
echo "-Parameter #1 is zero length.-" # Or no parameter passed.
else
echo "-Parameter #1 is \"$1\".-"
fi
variable=${1-$DEFAULT} # What does
echo "variable = $variable" #+ parameter substitution show?
# ---------------------------
# It distinguishes between
#+ no param and a null param.
if [ "$2" ]
then
echo "-Parameter #2 is \"$2\".-"
fi
return 0
}
echo
echo "Nothing passed."
func2 # Called with no params
echo
echo "Zero-length parameter passed."
func2 "" # Called with zero-length param
echo
echo "Null parameter passed."
func2 "$uninitialized_param" # Called with uninitialized param
echo
echo "One parameter passed."
func2 first # Called with one param
echo
echo "Two parameters passed."
func2 first second # Called with two params
echo
echo "\"\" \"second\" passed."
func2 "" second # Called with zero-length first parameter
echo # and ASCII string as a second one.
exit 0
In [4]:
%%bash
#!/bin/bash
# using stdout passing data
# Declare function
addup() # function to add the number to itself
{
echo "$((numvar + numvar))"
}
# MAIN
while : # start infinite loop
do
clear # clear the screen
declare -i numvar=0 # declare integer variable
# read user input into variable(s)
echo; echo
#read -p "Please enter a number (0 = quit the script): " numvar otherwords
numvar=100
if (( numvar == 0 )) # test the user input
then
exit $numvar
else
result=$(addup) # call the function addup
# and get data from function
echo "$numvar + $numvar = $result"
#read -p "Press any key to continue..."
fi
break # this is added by myself because I'd like to print the output in the notebook
done
In [8]:
!lsof / |grep "/home/chweng/.ipython"
In [11]:
!strace -c find /etc -name "python*"
In [17]:
!ltrace -c find /etc -name "python*"
In [31]:
%%bash
#Example 1: Printing the First Field of the /etc/hosts File to stdout
#cat /etc/hosts | awk '{print $1}'
#Pipes data to awk
awk '{print "field one:\t" $1}' /etc/hosts
#Uses /etc/hosts as an input file
#'{print}' #Prints the current record
#'{print $0}' #Prints the current record (more specific)
#'{print $1}' #Prints the first field in the current record
#'{print "field one:" $1}' #Prints some text before field 1
#'{print "field one:\t" $1}' #Prints some text, a tab, then field 1
#'{print "field three:" $3; print $1}' #Prints fields on two lines in
In [33]:
!awk ' { print "" ; print $0 }' ~/code/module08
1. ls -al /etc | awk '$1 ~ /^d/ {print "dir: ",$9}'
2. ll /etc | awk '$1 ~ /^d/ && $9 !~ /^\./ {print "dir: ",$9}'
3. ll /sbin |awk '/^-/ && $2 > 1 {print "file:",$9 "\t links: ",$2}'
4. cat /etc/services | awk '$1 == "ssh" {print "service: ",$1,$2}'
5. ss -an | awk '/^ESTAB/ && $4 ~ /:22$/ {print "ssh from:",$5}'
6. mount | awk '$5 ~ /ext[234]/ || $5 == "xfs" {print $3,"("$5")"}'
7. ps -ef | awk '$2 == 1 , $2 == 10 {print}'
In [36]:
!ls -al /home/chweng
In [35]:
!ls -al /home/chweng/ | awk '/^d/ {print "dir: ",$9}'
In [38]:
!mount |grep "ext"
In [39]:
!mount | awk '/ ext[234] / {print "device: ",$1,"\tmount point: " $3}'
In [42]:
!mount | awk '/ ext[234] / {print "device: %5s \tmount point: %5s",$1, $3}'
In [45]:
!ip addr show
select ipv4's ip:
In [46]:
!ip addr show | awk '/inet / {print $2}'
In [52]:
!cat /etc/passwd | awk -F : '/^chweng/ {print "id:",$1," \thome:",$6}'
chweng@VirtualBox:~$ sudo fdisk -l | awk '/^Disk \/dev\/[hs]d/ {print $2,$3,$4}'
/dev/sda: 1 TiB,
In [56]:
!cat /etc/group | awk -F : '/^sudo/ {print $1 ,"users are:", $4}'
In [58]:
import os
os.chdir("/home/chweng/code")
chweng@ubuntu221:~/code$ javac -d . TestDiceThrowEx1.java
chweng@ubuntu221:~/code$ ls
RoadLog exercises module03 module05 module07 tw
TestDiceThrowEx1.java module02 module04 module06 module08
chweng@ubuntu221:~/code$ java tw.loop.TestDiceThrowEx1
diceNumber=5
Try Again.
diceNumber=5
Try Again.
diceNumber=6
Try Again.
diceNumber=6
Try Again.
diceNumber=4
Try Again.
diceNumber=5
Try Again.
diceNumber=6
Try Again.
diceNumber=2
You Win.
In [69]:
%%bash
ls -l /home/chweng/code/exercises/ |awk '/^-/ && $2 = 1 {print "file:",$9 "\t links: ",$2}'
strace -c -f java tw.loop.TestDiceThrowEx1
In [70]:
!ps -ef | awk '$2 == 1 , $2 == 10 {print}'
#input data from nbafile file
1. awk '$3 == 82 {print $1," \t",$5}' nbafile
2. awk '$3 < 78' nbafile
3. awk '$2 ~ /c.*l/' nbafile
4. awk '$1 ~ /^s/ && $4 > 80 {print $1 "\t\t" $4}' nbafile
In [73]:
%%bash
echo "This is a book" | awk '
{ print "length of the string : ",$0," is : ",length($0) }'