Posts tagged 'bash'

Luca Lanziani

Read file in chunks in bash

How to read a file in chunks. You can optionally specify the starting point and the chunk size.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

function read_file_in_chunks { # FILENAME [START_FROM_LINE] [CHUNK_SIZE]
   FILENAME="$1" && shift
   START_FROM_LINE ...

Luca Lanziani

It's a Trap!

I do a big use of shell scripts, and many of them contain a for loop, do you know what normally happen when you press CTRL^C and the script is executing an action inside the loop?

for i in test{6..10}.com; do
    echo "pinging ${i}"; ping -c ...