One Day One Cmd

Place for playing with commands…

Monthly Archives: August 2010

Day27: $ grep multiple search

ODOC:Mutiple search using grep.
eg: $ grep -i ‘foss \| gnu \| linux \| os’ news.txt. It will return lines where ever the above 3 words r matching in the news.txt.

Day26 : $ grep

ODOC: $grep arul names.txt. It will return, matching patterns/characters in the names.txt file.It used to find the strings in any file or files in any directories.

eg: $grep -i ArUl names.txt. It ll do search by case-insensitive. -n for searching nos. -v will give non-matching characters of lines in the names.txt. πŸ™‚

Day 25 : pipe

ODOC:pipe(|).A pipe channels the output of one program to the input of another program.Use the vertical bar: | called as \’pipe\’ char.[\'rev\' = reverse the sting]…

ODOC:pipe the output of \’echo\’ into the program \’rev\’.eg:\$echo Happy | rev .Ans: yppaH. i.e.It will do both echo and rev program simultaneously using pipe:-)

Day 24 : $ sed

ODOC: $sed.Use the s/pattern/replacement/ command to substitute text matching the ‘pattern’ with the ‘replacement’. ….

eg: $ sed -e ’s/thru/through/g’ in-file >out-file.It will replace β€˜thru’ with β€˜through’ in in-file &stored in out-file./g for replacing in all occurances.:-)

Day 23: $ tr

ODOC:$tr start-set translates one set of charas to another.It replaces all chars in start-set with corresponding chars in end-set….

eg:$tr a-z A-Z< foo.txt.It will replace small a-z to A-Z in it. $tr -d a

Day 22: $ tac

ODOC: $tac foo.txt. It will print the content of foo.txt in reverse order. i.e. Its quitely opposite to $cat foo.txt.:-)

Day :21 $ split

ODOC: $split -l 10 foo.txt out_ .It will split the input foo.txt by 10 lines and saved into out_aa,out_ab,out_ac,etc.,correspondingly. i.e.Output files are named using the specified output name with aa, ab, ac, etc., added to the end of the prefix. πŸ™‚

Day 20: $ cat -n

ODOC: $ cat -n foo.txt.It will display each line of foo.txt with corresponding line numbers in front of every line.It counts lline no for the empty lines also:-)

Day 19: $ cut

ODOC: $ cut -c 3-10 foo.txt.It will cut characters from 3rd to 10th chars of each lines in foo.txt.It used to select columns/fields from each line of input. πŸ™‚

Day 18: $ uniq

ODOC: $uniq -u foo.txt.It prints the uniq lines of foo.txt. -d prints only duplicated lines. $sort -u foo.txt,ll return sorted & unique content of foo.txt. πŸ™‚