Powered by Drupal

Code

20
Jul

Replace commas with spaces using "cut"

# echo "test,test,test" | cut -d',' --output-delimiter=' ' -f1-
test test test

20
Jul

Bash loop with End of Line as delimiter

Here is how you do a for loop that uses the end of the line as the delimiter instead of space delimited.
The reason this is better is that you can set variable inside the loop and check them outside unlike doing it with a while read loop.
The testfile.data file can now have spaces on each line.

#!/bin/sh

IFS="
"

for i in `cat testfile.dat`
do
        CHECK="test"
        echo $i
done
echo ${CHECK}
Subscribe to RSS - Code