Reputation: 1
I have csv file having first column as shar-02-bc [0.49%] rip-086-cd [0.56%] . . In every cell there are 8 chars before the square braces. Is there any method to remove the square braces and it's contents. The modified csv file should contain the column as shar-02-bc rip-086-cd
Upvotes: 0
Views: 37
Reputation: 1863
If each row (not column) of the column is something like this:
shar-02-bc [0.49%] rip-086-cd [0.56%]
then you have a few options.
If you can treat each line like a list, then use lsearch
to find the items which aren't inside square brackets (the glob pattern needs to backslash escape the square brackets)
lsearch -all -not -inline $line {\[*\]}
or you could treat each like like a dictionary with alternating key value pairs:
dict keys $line
If you treat each line like a string, then regsub
is another option. This replaces any non-whitespace inside square brackets with an empty string.
regsub -all {\[\S+\]} $line ""
Upvotes: 1