Thursday, February 28, 2013

List files within date range

Problem: List files from january 26 to february 25


Files:


asterlui@192.168.1.1:/usr/src/test$ ls -l
total 0
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130126
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130127
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130225
-rw-r--r-- 1 root root 0 Mar  1 07:32 log_20130227


command: ls log_* | awk -F \_ -v start=20130126 -v end=20130225 '{d=substr($1,9); if (d>=start&&d<=end) print}'


asterlui@192.168.1.1:/usr/src/test$ ls log_* | awk -F \_ -v start=20130126 -v end=20130225 '{d=substr($0,9); if (d>=start&&d<=end) print}'
log_20130126
log_20130127
log_20130225

Wednesday, February 13, 2013

Debian Offline apt-get repositories

How to install debian packages/applications offline?

SOURCE MACHINE:
# make a directory to store the offline packages.
mkdir /luirepo

# copy all packages found in your cache archives directory.
cp /var/cache/apt/archives/*.deb /luirepo

# go to your directory with the copied packages.
cd /luirepo

# make packages.gz to be needed later on.
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

DESTINATION MACHINE:
# copy the folder "luirepo" in your new machine and place it in the root folder. you can use winscp for copying.
/luirepo

# edit the sources.list of your new machine. point it to the directory.
nano /etc/apt/sources.list

---------------------------------
deb file:/luirepo/ /
---------------------------------

# you're done! try to update run some installations offline

#example 1:
apt-get update

#example 2:
apt-get install build-essential



Thursday, February 7, 2013

Shell Script to Search Words in between Letters

In our example below.. It will display all the words that starts with letter "B" and ends with letter "D".

linux command:

wget -nv -O - "http://www.morewords.com/?=b*d" | awk '/word/' | awk '/class/' | awk 'sub(".........$", "")' | cut -b 1-31 --complement | rev | cut -d/ -f2- | rev

sample output:



baaed
babbitted
babbled
babied
babyhood
baccated
bached
bachelorhood
backbend
.
.
.
byword



Happy Scripting!