Posts

Showing posts with the label bash

Create sequence with zero padding

Hmm I got to pull series of git source from 01-13. But I'm too lazy so I googled then I found program `seq` I don't know it much but it can >>> seq 1 10 1 2 3 4 5 6 7 8 9 10 >>> seq -w 1 10 01 02 03 04 05 06 07 08 09 10 >>> seq -w 01 10 01 02 03 04 05 06 07 08 09 10 Aha, So I see the light!! >> for id in `seq -w 01 13`; do git pull XXXXX$id; done; Yeh,! Many thank to links below!! :) http://stackoverflow.com/questions/6446672/generating-huge-lists-of-numbers http://stackoverflow.com/questions/8789729/zero-padding-in-bash

Grep option from Jua

Today tasks, when we want to grep something we use >> ls -l | grep Jua tell me, if i need everything except >> ls -l | grep -v    # I think it's come from exclude by help said invert match!!! ### Thank Jua :) Anyway, we can use some simple regular expression by >> ls -l | grep -e [regex] such as >> ls -l | grep -e ^B

Bash Shortcuts

These content are from SKORKS ( http://www.skorks.com/2009/09/bash-shortcuts-for-maximum-productivity/ ), Thanks Alan Skorkin Command Editing Shortcuts Ctrl + a  – go to the start of the command line Ctrl + e  – go to the end of the command line Ctrl + k  – delete from cursor to the end of the command line Ctrl + u  – delete from cursor to the start of the command line Ctrl + w  – delete from cursor to start of word (i.e. delete backwards one word) Ctrl + y  – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor Ctrl + xx  – move between start of command line and current cursor position (and back again) Alt + b  – move backward one word (or go to start of word the cursor is currently on) Alt + f  – move forward one word (or go to end of word the cursor is currently on) Alt + d  – delete to end of word starting at cursor (whole word if cursor is at the beginning of wor...

BASH scripting TIP #1

In bash script file $? - store exit value of last command that was executed $* - store all args "$@" - store all args, individually with qoute "$1", "$2" $1 - first arg $2 - second arg $n - nth arg

The combination of xargs

Assume that you : Have folder "mylist" that contain a lot of files such as "a.php", "uud.php", "ad.py".... You want to : Add new extension ".du" to any files in this folder I can do : ~/mylist$ ls | xargs -I f mv f f.du             # god bless -I :o Or I can do : ~/mylist$ find . -name '*.py' | xargs -I f mv f f.du        # just add new extension for *.py * aha , i think that a lot of combination could made :) ** next time, it should be rename extension not add it. (my eng is suck)

Insert text in the middle of text file by sed

I found problem on how to add text line in the middle of the hosts file. Just like below 127.0.0.1   localhost < i want to add text line here > xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx and want to use 'sed', My friend, Sajal Kayan (God of Scripting) introduce me on ref#1, actually I quite not understand that. So he get me 2 approaches. #1   for each time i have to add text line, then do   >>> sed -i 's/127.0.0.1   localhost/127.0.0.1   localhost\n this is new line /' /etc/hosts   >>> sed -i 's/127.0.0.1   localhost/127.0.0.1   localhost\n this is new line 1/' /etc/hosts   >>> sed -i 's/127.0.0.1   localhost/127.0.0.1   localhost\n this is new line 2/' /etc/hosts   then we'll get   127.0.01   localhost   this is new line 2   this is new line 1   this is new line   this is good enough if we don't care about the order. But if you care , Sajal has...