How can I get sed to only match to the first occurrence of a character?

user2871860

I'm using GNU Sed 4.2.1. I'm trying to replace the second field in the following line (the password in /etc/shadow). Awk is not an option.

username:P@s$w0rDh@$H:15986:0:365::::

I've tried

sed -i 's/\(^[a-z]*\):.*?:/\1:TEST:/'

but nothing. I've tried many variations but for some reason I can't get it to only match that field. Help?

nosid

Use [^:]* to match everything up until the next :

sed -i 's/^\([^:]*\):\([^:]*\):/\1:TEST:/'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I replace the first occurrence of a character in every word?

From Dev

How can I get only the first line from a string?

From Dev

How to remove only the first occurrence of a line in a file using sed

From Dev

Using sed how to remove last character only in the first line

From Dev

How can i split a string into two on the first occurrence of a character

From Dev

regex replace only the first occurrence of every match

From Dev

Match only the first occurrence of a phrase

From Dev

Match only first occurrence of digit

From Dev

How can I replace the eighteenth character before space character (without match this only match the space character )?

From Dev

How can I find start and end occurrence of character in Python

From Dev

How can I replace the first occurrence of a character in every word?

From Dev

Java, Replace only the first occurrence of a Sharp Character (#)

From Dev

regex match first occurrence of a single character

From Dev

Delete only first occurrence of character using tr

From Dev

regmatch_t how can i get match only?

From Dev

How do I exclude match and change only specific character with sed

From Dev

How do I replace the last occurrence of a character in a string using sed?

From Dev

sed - trying to replace first occurrence after a match

From Dev

Sed : replace words only with first occurrence of string in the line not till last match

From Dev

How to match only first occurrence of space at line

From Dev

How to *return* *only* the nth occurrence of a regex match using sed?

From Dev

How do I have sed only perform actions on the first match?

From Dev

how to insert file contents on match using sed - first occurrence only

From Dev

sed + remove character on the first match or on the second match

From Dev

regex replace only the first occurrence of every match

From Dev

Match only the first occurrence of a phrase

From Dev

How to use sed to replace only the first occurrence?

From Dev

sed - only get single occurrence

From Dev

How can I change the third occurrence of a word in a file using sed?

Related Related

  1. 1

    How can I replace the first occurrence of a character in every word?

  2. 2

    How can I get only the first line from a string?

  3. 3

    How to remove only the first occurrence of a line in a file using sed

  4. 4

    Using sed how to remove last character only in the first line

  5. 5

    How can i split a string into two on the first occurrence of a character

  6. 6

    regex replace only the first occurrence of every match

  7. 7

    Match only the first occurrence of a phrase

  8. 8

    Match only first occurrence of digit

  9. 9

    How can I replace the eighteenth character before space character (without match this only match the space character )?

  10. 10

    How can I find start and end occurrence of character in Python

  11. 11

    How can I replace the first occurrence of a character in every word?

  12. 12

    Java, Replace only the first occurrence of a Sharp Character (#)

  13. 13

    regex match first occurrence of a single character

  14. 14

    Delete only first occurrence of character using tr

  15. 15

    regmatch_t how can i get match only?

  16. 16

    How do I exclude match and change only specific character with sed

  17. 17

    How do I replace the last occurrence of a character in a string using sed?

  18. 18

    sed - trying to replace first occurrence after a match

  19. 19

    Sed : replace words only with first occurrence of string in the line not till last match

  20. 20

    How to match only first occurrence of space at line

  21. 21

    How to *return* *only* the nth occurrence of a regex match using sed?

  22. 22

    How do I have sed only perform actions on the first match?

  23. 23

    how to insert file contents on match using sed - first occurrence only

  24. 24

    sed + remove character on the first match or on the second match

  25. 25

    regex replace only the first occurrence of every match

  26. 26

    Match only the first occurrence of a phrase

  27. 27

    How to use sed to replace only the first occurrence?

  28. 28

    sed - only get single occurrence

  29. 29

    How can I change the third occurrence of a word in a file using sed?

HotTag

Archive