Reputation: 173
I'm trying to grab line 2, a single character ; that keeps reoccurring during the generation of one of my config files. It's breaking my builds. I need to replace the ; with an empty character or just remove the line entirely. The issue I'm having is grabbing that character and none of the other ; characters.
- HOSTS all
;
jjlkasd;
- aslkdjasd;
Upvotes: 1
Views: 26
Reputation: 103754
Given:
$ echo "$inp"
- HOSTS all
;
jjlkasd;
- aslkdjasd;
You can use sed
:
$ echo "$inp" | sed 's/^;$//'
- HOSTS all
jjlkasd;
- aslkdjasd;
Or if there is any possibility of leading or trailing spaces:
$ echo "$inp" | sed 's/^\s*;\s*$//'
- HOSTS all
jjlkasd;
- aslkdjasd;
Or, if you want to delete the entire line:
$ echo "$inp" | sed '/^\s*;\s*$/d'
- HOSTS all
jjlkasd;
- aslkdjasd;
Upvotes: 1