HowTo write column data in gtkDialog TableBox? [Solved]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

HowTo write column data in gtkDialog TableBox? [Solved]

#1 Post by sunburnt »

The data for the gtkTableBox looks like this:

Code: Select all

sda1|M|
sda3|M|
sda5||
sda6|M|
sdb1||
sdb5||
sr0||
sr1||
The sed command I`ve used before doesn`t want to do the job, ${1} is the drive (sda3):

Code: Select all

echo "$(</tmp/drvinfo)" |sed "s/\(${1}||\).*/\1{B}/" > /tmp/drvinfo
I`m trying to get it to put a "B" on the end, like this: " sda3||B " and remove it: " sda3|| "
I also need to write and remove the middle position, like this: " sda3|M| " and "sda3||"

So for a given row (record) I need to write a given column (field) independantly.
I could do this in several lines of code, but I`m sure sed will probably do it in one line...
Last edited by sunburnt on Thu 11 Mar 2010, 06:27, edited 1 time in total.

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#2 Post by sunburnt »

I didn`t find how to make sed do it in one line, but I got close...

Code: Select all

	ROW=`echo "$(<$drvINFO)" |grep $1`
	COL=`echo "$ROW" |cut -d '|' -f 3`
	if [ -z "$COL" ];then																																# set drive to boot mount
		NEW="$ROW"B
		echo "$(<$drvINFO)" |sed "s/$ROW/$NEW/" > $drvINFO
		echo $1 >> $drvBOOT
	else																																									# set drive to not boot mount
		NEW=`echo $ROW |sed 's/B//'`
		echo "$(<$drvINFO)" |sed "s/$ROW/$NEW/" > $drvINFO
		echo "$(<$drvBOOT)" |grep -v $1 > $drvBOOT
	fi
This toggles the column data for the input file for a gtkDialog TableBox.
The TableBox reads the file $drvINFO, variables $ROW, $COL, and $NEW are obvious.

Post Reply