0

how can i use sed in a special way to remove apart of a special character

sed s/^}$//g > file 

doesn't do anything, I'm trying to remove the beginning of every line up to the bracket, so that this line

Aug 09 19:46:15 inspire NetworkManager[747]: <info>  [1533861975.9201] dhcp4 (wlp3s0b1): state changed unknown 

looks like this

dhcp4 (wlp3s0b1): state changed unknown
1

I'm not sure why you would expect that to work, however if you want to match (and remove) the longest string ending in ] and its trailing space, you can use sed 's/.*] //'

Ex.

echo 'Aug 09 19:46:15 inspire NetworkManager[747]: <info>  [1533861975.9201] dhcp4 (wlp3s0b1): state changed unknown' | 
  sed 's/.*] //'
dhcp4 (wlp3s0b1): state changed unknown

FYI, ^}$ would match } on a line by its own (i.e. anchored to both the start of the line ^ and to the end of the line $)

  • You're a God, Thank you, why doesn't sed 's/^*]$//g' work, doesn't that say beginning with anything up to ] the end – user610658 Aug 10 '18 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy