0

I have a log file of errors captured in my database, the file contains a list of the records that had errors and were not updated. The record names are 10 digits and start with a strA:

Error: could not save changes to record strA5903427123
Error: could not save changes to record strB4403298440
Error: could not save changes to record strC5903427342
Error: could not save changes to record strD4403298988
Error: could not save changes to record strE5903427298
Error: could not save changes to record strF4403298232
Error: could not save changes to record strG5903427455
Error: could not save changes to record strH4403298223

I want to extract the list of ten digits and A and remove "Error: could not save changes to record str", how can I do it in bash, this is a very long list and I have many files like this one everyone for the database.

1

Is this what you want?

sed -e 's/^.*str//' test.in
  • @Gabi ... you need to edit the question. start with a strA is mentioned instead of start with a str – msp9011 Oct 9 '18 at 20:05
1

using grep to list the 10 digit ID that starts with A

grep -Eo "A[0-9]{10}" file

output

A5903427123

To list the 10 digit ID that starts with any uppercase alpha.

grep -Eo "[A-Z][0-9]{10}"  file

A5903427123
C5903427342
D4403298988
E5903427298
F4403298232
G5903427455
H4403298223
1

You can do it in awk as follows:

awk '{print $8}' file | tr -d "str"

A5903427123
B4403298440
C5903427342
D4403298988
E5903427298
F4403298232
G5903427455
H4403298223

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.