what i want to achieve is if the line has ',' at the end it deletes it... and also spaces(or tabs) before or after the line....
i tried echo "reserved1 varchar(255)," | cut -d ',' -f1 | sed 's/^[ ]//g;s/[ ]$//g'
but this willl not work for all conditions say if there is , inbetweeen the line...
---------- Post updated at 02:38 PM ---------- Previous update was at 02:07 PM ----------
i was using
linexT=$( echo $linexT | sed 's/^[ ]*//g;s/[ ]*$//g' )
len=${#linexT}
echo "len: $len"
charlast=${linexT:$len-1:$len}
if [[ "$charlast" = "," ]]
then
line11=${linexT:0:$len-1}
else
line11=$linexT
fi
the above since many days but the above doesnt work for few scenarios.. so is there any one liner for this.. which works for all the scenarios mentioned in my previous post?
consider the content of the variable $line11 is any of the below
line11="isoSizeKB text NOT NULL,"
similarly below ones....
reserved1 varchar(255),
or
KEY `deviceId` (`deviceId`)
or
`d5` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
or
`dHead` enum('HistoryInfo','Diversion') COLLATE utf8_unicode_ci,
or
`ePR` int(11) DEFAULT '0',
or
PRIMARY KEY (`id`)
respectively...
that is it should delte ',' (comma) present at the end of the line if present else not.. also it should delete empty spaces before the line (either n spaces or tabs)
i dont want to input any file to the command... the lines will be stored in a variable say $line11 i want to modify it then and there itself.. or modify it and store it in another variable
---------- Post updated at 03:22 PM ---------- Previous update was at 03:18 PM ----------