Reputation: 32306
How do I remove the text till the first ( and after )?
INSERT INTO `todel` VALUES (1,'akbar\'s','Mumbai, Delhi road, India');
INSERT INTO `todel` VALUES (2,'amar\"s','South Africa, ghana');
The expected output is like this...
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'
Upvotes: 2
Views: 6345
Reputation: 246744
awk can take a regular expression as field separator, so use either parenthesis as the field separator and just emit the 2nd field:
awk -F'[()]' '{print $2}' filename
Upvotes: 1
Reputation: 25599
Ruby(1.9+)
$> ruby -ne 'print $_.sub(/.*\(|\).*$/,"")' file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'
or the shell(bash)
$> while read -r line; do line=${line#*(}; echo ${line%)*}; done <file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'
or awk
$> awk '{sub(/.*\(/,"");sub(/\).*/,"")}1' file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'
or sed
$> sed -rn 's/.*\(//;s/\).*//p' file
1,'akbar\'s','Mumbai, Delhi road, India'
2,'amar\"s','South Africa, ghana'
Upvotes: 2
Reputation: 14137
You can remove everything from beginning of line until the first (
and from (including) the last )
till the end of line with sed
:
sed -r 's/^[^(]*\(.*)\)[^)]*$/\1/'
Upvotes: 0