1

I need to delete or replace the third ":" (colon) with a space. I can't do it at a certain index because the entries differ in length.

u:Testuser:rw:/home/user1/temp
g:Testgroup:-:/home/user2/temp

Result should look like this:

u:Testuser:rw /home/user1/temp
g:Testgroup:- /home/user2/temp

Is there a way to 1) delete a specific character and 2) to insert a character before/after a specific character? I couldn´t find a solution, I am a beginner unfortunately.

2
  • This could easily be done with bash string manipulation. Or through awk. Or even sed. Commented Jan 4, 2019 at 16:38
  • I dont know how to tell the script to delete/insert at the third colon. Commented Jan 4, 2019 at 16:45

3 Answers 3

2

Thanks for the answer, I did it myself

g:Testgroup:-:/home/user2/temp | sed s/':'/' '/3
Sign up to request clarification or add additional context in comments.

Comments

0

A dirty solution:

$ cat 54042857.txt
u:Testuser:rw:/home/user1/temp
g:Testgroup:-:/home/user2/temp

$ awk -F ':' ' { print $1":"$2":"$3" "$4 } ' 54042857.txt 
u:Testuser:rw /home/user1/temp
g:Testgroup:- /home/user2/temp

Comments

0

Using parameter expansion:

$ foo='u:Testuser:rw:/home/user1/temp'
$ printf '%s\n' "${foo%":${foo#*:*:*:}"} ${foo#*:*:*:}"
u:Testuser:rw /home/user1/temp

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.