Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Unix (http://www.go4expert.com/articles/unix/)
-   -   Bash Simple Tricks (Continuation) - Part 3 (http://www.go4expert.com/articles/bash-simple-tricks-continuation-part-3-t24983/)

lionaneesh 15Feb2011 23:18

Bash Simple Tricks (Continuation) - Part 3
 
This is continuation of my previous articles .. Please don't miss them :-
  1. Bash Simple Tricks
  2. Bash Simple Tricks (continuation)
Again I am following a question – solution approach to demonstrate my scripts..

Scripts



How to 'cat'(print) all the files in a folder

Solution :-

Code:

#!/bin/bash

cat `ls`

ls output :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ ls
char2.sh  displayA.sh  endZ.sh  file1  ls.sh  vovelFile.sh

Running :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ ./ls.sh
#!/bin/bash

cat $1 | grep '..[eE]' | wc -l
#!/bin/bash

cat $1 | grep ^[aA] | wc -l
#!/bin/bash

cat $1 | grep [z]$ | wc -l
aaessss
aaaesss
aaaaaaaa
lionaneesh
ssssssssss
#!/bin/bash

cat `ls`
#!/bin/bash

ls | grep ^[aeiouAEIOU] | wc -l

cat(Print) all the .txt files in a folder

Solution :-
Code:

#!/bin/bash

cat `ls | grep .txt`

ls output :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ ls
char2.sh    endZ.sh  ls.sh    txt2.txt  vovelFile.sh
displayA.sh  file1    txt1.txt  txt.sh

Using :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ sh txt.sh
WOOOOOOWWWWWW!!!

Its file no 1 named txt1
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hello !!!!!! Hi Wassup

This is file no 2 named txt2

Write a bash script to display todays date and time..
Code:

aneesh@aneesh-laptop:~/articles/Bash$ cat date.sh

#!/bin/bash

echo "Today is `date`"

Using :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ chmod +x date.sh

aneesh@aneesh-laptop:~/articles/Bash$ ./date.sh

Today is Tue Feb 15 22:23:57 IST 2011

Write a bash script to output the date and time in audio format(speak)
Code:

#!/bin/bash

espeak "Today is `date`"

Using :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ chmod +x date2.sh

aneesh@aneesh-laptop:~/articles/Bash$ ./date2.sh

Write a bash script to maximize all the windows opened after a specified no of seconds..

Solution :-
Code:

#!/bin/bash

sleep $1

maximus

Using :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ chmod +x maximise.sh

aneesh@aneesh-laptop:~/articles/Bash$ ./maximise.sh 2

How to download youtube videos with bash ?
Code:

#!/bin/bash

youtube-dl $1

Using :-
Code:

aneesh@aneesh-laptop:~/articles/Bash$ chmod +x youtube.sh

aneesh@aneesh-laptop:~/articles/Bash$ ./youtube.sh http://www.youtube.com/watch?v=m8Dd7rjmEW4


lionaneesh 18Feb2011 21:04

Re: Bash Simple Tricks (Continuation) - Part 3
 
If you are viewing this article leave a comment whether you like it or not...Or what you want more from the article...Etc..etc...

humpakistani 18Mar2011 16:39

Re: Bash Simple Tricks (Continuation) - Part 3
 
yes i have try the last one and i think that was the best according to me

lionaneesh 18Mar2011 16:56

Re: Bash Simple Tricks (Continuation) - Part 3
 
Quote:

Originally Posted by humpakistani (Post 80827)
yes i have try the last one and i think that was the best according to me

Downloading videos!!
yeah!! Its good!


All times are GMT +5.5. The time now is 21:14.