Tags » Shell Script

remove first and last char of string

using bash

MYVAR=abcd; echo ${MYVAR:1:-1}

using sed

echo abcd | sed s'/^.\(.*\).$/\1/'

using awk

echo abcd | awk '{print substr( $0, 2, length($0)-2 )}'
Shell Script

check if same row exist in two files

while read i;do egrep ^$i$ file2 && echo $i >> exist.out || echo $i >> non_exist.out; done < file1
Shell Script

using continue inside of loop in bash

It will jumps the 2, printing only 1 3 4 5

for i in {1..5};do
        [ $i -eq 2 ] && continue
        echo $i
done
Shell Script

format number on linux

Add comma for thousand number, printf version

printf "%'d\n" 1234567

Add comma for thousand number, numfmt version

numfmt --group 1234567

Add comma for thousand number, … 11 more words

Shell Script

delete a column with cut command

delete first column

cut -d: -f1 --complement /etc/passwd

delete last column

rev /etc/passwd | cut -d: -f1 --complement | rev

delete columns one and four… 18 more words

Shell Script

manipulate params passed to bash script

print all params passed to bash script

for i in $*;do echo $i; done

remove first param passed to bash script

for i in ${*:1-$#};do echo $i; done
… 46 more words
Shell Script

How to use Oracle v$ views in Shell Script

It is difficult to use v$ views in Shell script to fetch any Oracle Database internal data, due to the special character $ associated with the views.But it can be achieved by using an backspace. 185 more words

Oracle