|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Gsub regex not working
I have a number of files that I pass through awk/gsub. I believe to have found a working regex and on 'test bed' sites it matches, however within gsub it does not. Examples: Initial data: Code:
/Volumes/Daniel/Public/Drop Box/[sage]_Hellsing_Ultimate_OVA_-_10_[720p-AAC][4B4C84C5].mkv gsub & regex: Code:
gsub("\[[^\]]+\]",""I've been able to remove mostly everything with other expressions but the first brackets "[sage]" still remain. The content within the brackets varies a lot (e.g. [SFW-sage]. I'd like to keep the script as simple as possible (one line). |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
One way to do it is using [ and ] as field separators is: Code:
awk -F '[]]|[[]' '{for(i=1; i<=NF; i+=2)printf("%s",$i);printf("\n")}' inor using gsub(): Code:
awk '{gsub("[[][^]]+[]]","")}1' inIf you're using a Solaris system, use /usr/xpg4/bin/awk or nawk instead of awk. Last edited by Don Cragun; 01-07-2013 at 10:32 PM.. Reason: provide two ways to do it |
| The Following User Says Thank You to Don Cragun For This Useful Post: | ||
unknownn (01-07-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
awk gives me: Code:
awk: can't open file in source line number 1 nawk is unavailable. Edit: Your second solution works wonderfully. Thank you very much. Last edited by unknownn; 01-07-2013 at 10:43 PM.. |
|
#4
|
|||
|
|||
|
try: Code:
gsub("[[][^]]*]","") |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
You didn't say what the name was for the file that contains your "initial data". Both of the scripts I provided assume that the text you want to process is in a file named
in . I've tried both of them on Mac OS X Version 10.7.5. Since OS X is a Mac OS X system (not a Solaris system), use awk.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| GSUB/Regex Help | nitrobass24 | Shell Programming and Scripting | 6 | 08-22-2012 04:41 PM |
| awk gsub(): general regex | lucasvs | UNIX for Dummies Questions & Answers | 9 | 04-05-2012 03:48 AM |
| matching a regex using egrep not working | skrtxao | Shell Programming and Scripting | 6 | 11-28-2011 11:16 AM |
| gnu sed regex grouping not working? | Allasso | Shell Programming and Scripting | 3 | 01-20-2009 08:25 PM |
|
|