0

I have been facing issues with using regex with sed. I have a string like :

Call stack: [thread 0xac0aaa28]: | start | main main.m:37 | UIApplicationMain | GSEventRun | GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoSource1 | __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ | mshMIGPerform | _XCopyAttributeValue | _AXXMIGCopyAttributeValue | _copyAttributeValueCallback | -[NSObject(AXPrivCategory) accessibilityAttributeValue:] | -[UITableViewCellAccessibilityElement _accessibilityIsTableCell] | -[UITableViewCellAccessibilityElement tableViewCell] | -[UITableViewAccessibility(Accessibility) accessibilityCellForRowAtIndexPath:] | -[UITableView(UITableViewInternal) _createPreparedCellForRowAtIndexPath:] | -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] | -[MailViewController tableView:cellForRowAtIndexPath:] | +[NICellFactory tableViewModel:cellForTableView:atIndexPath:withObject:] NICellFactory.m:89 | +[NICellFactory cellWithClass:tableView:object:] NICellFactory.m:67 | -[SwipableTableViewCell shouldUpdateCellWithObject:] | -[SwipableTableViewCell updateCellWithObject:] | -[ThreadCellFrontView updateCellWithObject:] | -[ThreadSummaryView updateWithNugget:] | -[JavaUtilLinkedList init] LinkedList.m:49 | -[JavaUtilLinkedList initJavaUtilLinkedList] LinkedList.m:40 | +[NSObject alloc] | +[NSObject allocWithZone:] | _objc_rootAllocWithZone | class_createInstance | calloc | malloc_zone_calloc

which has instances like main.m:37 |, LinkedList.m:95 |, NICellFactory.mm:89 | etc i.e in text mate I can match these occurences with using the regex

[a-zA-z]+[.][m]+[:]+[0-9]+[ |]+

Now when I try to do the same thing in sed using

sed 's/\[a-zA-z]+[.][m]+[:]+[0-9][ |]+/ /g'

Sed does not seem to replace these instances. I have tried using backlashes too i.e

sed 's/\[a-zA-z\]+\[\.\]\[m\]+\[:\]+\[0-9\]+\[ |\]+/ /g'

Still sed does not replace such occurences.

Can someone help me understand what am I doing wrong?

Thanks

2 Answers 2

1

The backslashes you added for no good reason are the problem. Also your sed dialect may not support + repetition out of the box - try with * instead, or look for a -r or -E option in your sed manual page.

Sign up to request clarification or add additional context in comments.

Comments

1

The following works for me:

sed -i.bck  "s/[a-zA-Z][a-zA-Z]*\.mm*::*[0-9][0-9]*\s|/ /g"  prova_sed.txt

It creates a backup file just in case.

May sed doesn't seem to support the +, \w and \d syntax so I've used [a-ZA-Z][a-zA-Z]* instead of [a-zA-Z]+, mm* instead of m+ and so on.

Also note that you don't need to put single characters inside brackets so [\.][m]+[:]+ can be replaced with \.mm*::*

If your sed version supports the -r option the whole thing could be simplified to

sed -i.bck  "s/[a-zA-Z]+\.m+:+[0-9]+\s|/ /g"  prova_sed.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.