How to Delete the String Pattern from a File Between 2 Colon Character
Searched a Lot Lot but Didn't Find Any Solution. for Example: If String Is A12345: Hello World: Hello World Again: Other String Output: A12345: :Hello World...
Searched a lot lot but didn't find any solution.
for example: if string is
a12345:hello world:hello world again:other string
output:
a12345::hello world again:other string
so I just wanted to delete the content between 1st and 2nd colon character
Any help would be appreciated.
Thanks,
2 Answers
Use sed:
sed 's/:[^:]*/:/'
- first
:- match colon [^:]*- match any number of characters which are not a colon- last
:- replace the match with colon, because your match includes the first colon, but from your output I see you want to keep it.
Using sed:
sed -i 's/:[^:]*/:/' file_name
Using awk:
awk -F':' -v OFS=":" '{$2="";print}' file_name