Skip to content

3. Batch Operations

gitarunprasanna83 edited this page Aug 12, 2019 · 9 revisions

By now, you know how to use commands to complete an operation on text files, combine two or more commands using PIPES. In this exercise, you will learn how to make executable files in simple bash script

Useful tip:

Install an advanced notepad. Examples: For linux - Kate, For Mac - BBedit, For Win - Notepad++

They are really handy with syntax highlighting, auto indenting features, execution in shell etc.,

Create a bash file:

  1. Open BBedit and type the following lines below

bashscript_1

  1. Save as .. bashscript1.sh

** Line 5, shows the same one-liner that we created using pipe in File operations section **

  1. In terminal type -- > bash bashscript1.sh

Let's decorate it more to get more information!

Execute it and see the output.. You can compare the output with previously generated gene list using diff !

decoration

What's the big deal ?

Simplify your life !

Combine group of commands to execute one line at a time, process repeated operations with multiple files in a loop. For this task, some practice on wild cards is essential !

  1. Make a directory “WildCards
  2. Enter inside the directory
  3. touch {1..3}.txt
  4. touch {a..c}.txt
  5. touch cat_{001..002}.txt
  6. touch rat_{10,20,30}_{a,b,c}.txt
  7. touch AA.txt [How many files you have in total ? ls | wc -l]
  8. Display txt files with only one character that is number -- > ls [0-9].txt
  9. Display txt files with only one character that is a letter -- > ls [a-z].txt
  10. Display txt files with only one character that is a letter or word -- > ls ?.txt [pipe with wc -l to check total number of files in this category]
  11. Display txt files not starting with a capital letter -- > ls [!A-Z]*.txt
  12. Display txt files ending with an alphabet -- > ls *_[a-z].txt
  13. Display file that have 10 in between their names -- > ls *10*.txt

Now you are ready a batch operation !

All the text files you created are empty. Fill all of them with a line.

  1. Create a bash file 'add_a_text.sh' and type the following [Carefully indent]:

Simplebatch

Here filelist is called "Variable"

Clone this wiki locally