I've just started playing with Linux again for the upteenth time, and I think this time it might stick. One of my favourite things is the powerful bash shell and the ease with which you can manipulate data using it.

It's really easy to make scripts to manipulate data using pipes and whatnot, here are a few of mine:

pyline

Take a statement as a parameter (enclosed in quotes), and execute it for each line on STDIN. Can use this for basic text manipulation. Could be extended to create additional context for processing. I know there we have awk and sed for this kind of thing but eh, I know python

#!/usr/bin/python import sys i = 0 for line in sys.stdin: line = line[:-1] exec sys.argv[1] i += 1

eg print every third line:

cat txtfile | pyline "if i%3: print line"

try

Try a command until it executes successfully. Optionally takes the number of times to try until it is successful.

#!/bin/bash COUNT=-1 if [[ $1 =~ ^[0-9]+$ ]]; then COUNT=$1 shift fi STATUS=0 while [ "$COUNT" -ne 0 ]; do let COUNT-=1 $* STATUS=$? if [ $STATUS -eq 0 ]; then exit $STATUS fi done exit $STATUS

eg to attempt to connect to a wireless network 5 times (sometimes dhcp times out):

try 5 netcfg mywireless

Post some of yours!

edit: bugfix

Last edited by Mashi (2008-10-10 01:11:19)