I need to write a sed command that reads from a file and replaces the first character in each line with 0, only in the event that the first and second character in that line is a digit (and leave the rest of the lines intact).
1 Answer
You can find lines that begin with two digits using either ^[0-9][0-9] or ^[0-9]\{2\}
Then you can replace a single character with 0 using s/./0/
Putting it together,
sed '/^[0-9][0-9]/ s/./0/' somefile
or
sed '/^[0-9]\{2\}/ s/./0/' somefile

man sedorinfo sedand tutorials like grymoire.com/Unix/sed.html and code.snipcademy.com/tutorials/shell-scripting/sed/introduction