Posts

Showing posts with the label Shell. Linux

`sed' is a stream editor

Sed is the ultimate s tream ed itor. If that sounds strange, picture a stream flowing through a pipe. Okay, you can't see a stream if it's inside a pipe. That's what I get for attempting a flowing analogy. You want literature, read James Joyce. Examples:- [root@rhel6 rajesh]# echo day day [root@rhel6 rajesh]# echo day | sed s/day/night/ night [root@rhel6 rajesh]# echo "This is my data.." | sed s/my/your/ This is your data.. [root@rhel6 rajesh]# [root@rhel6 rajesh]# echo EVERYDAY | sed 's/day/night/' EVERYDAY [root@rhel6 rajesh]# [root@rhel6 rajesh]# echo EVERYDAY | sed 's/day/night/i'        //"i" switch to ignore case-sentivity EVERYnight [root@rhel6 rajesh]# echo "one two three, one two three four three two one one hundred" | sed 's/one/ONE/' ONE two three, one two three four three two one one hundred [root@rhel6 rajesh]# echo "one two three, one two three four three two one one hundred...

adding date to a filename

 Spliting filename & extension :- Option, 1 ========================================================= [rajesh@rhel6 ~]$ FILE=somefile.txt [rajesh@rhel6 ~]$ echo $FILE somefile.txt [rajesh@rhel6 ~]$ NAME=${FILE%.*} [rajesh@rhel6 ~]$ echo $NAME somefile [rajesh@rhel6 ~]$ EXT=${FILE#*.} [rajesh@rhel6 ~]$ echo $EXT txt [rajesh@rhel6 ~]$ DATE=`date +%d-%m-%y` [rajesh@rhel6 ~]$ echo $DATE 18-06-13 [rajesh@rhel6 ~]$ NEWFILE=${NAME}_${DATE}.${EXT} [rajesh@rhel6 ~]$ echo $NEWFILE somefile_18-06-13.txt [rajesh@rhel6 ~]$ Option,2 :However, this won't work with multiple "." in the file name. ========================================================= [rajesh@rhel6 ~]$ echo $FILE somefile.txt [rajesh@rhel6 ~]$ [rajesh@rhel6 ~]$ NAME=`echo $FILE | cut -d. -f1 ` [rajesh@rhel6 ~]$ echo $NAME somefile [rajesh@rhel6 ~]$ EXT=`echo $FILE | cut -d. -f2` [rajesh@rhel6 ~]$ echo $EXT txt

15 Bash For Loop Examples for Linux / Unix / OS X Shell Scripting

Ref. to https://www.youtube.com/watch?feature=player_embedded&v=ocXb3qeg7Es