Reputation: 355
i have a file like this
MY-27125:some text
MY-27132:some text
MY-26565:some text
some text
MY-26097:some text
MY-27129:some text
MY-27211 && MY-26565:some text
some another text
MY-27175/MY-27147:some text
MY-27159\MY-27149:some text
MY-26747,MY-26945:some text
MY-20811 MY-26889:some text
i want to use sed or notepad++ or awk to have only text starting with MY-[5 digit number].
Output should be like below
MY-27125
MY-27132
MY-26565
MY-26097
MY-27129
MY-27211
MY-27175
MY-27159
MY-26747
MY-20811
MY-26565
MY-27147
MY-27149
MY-26945
MY-26889
Upvotes: 1
Views: 74
Reputation: 10039
sed -n "/\(MY-[0-9]\{5\}\).*/ s//\1/p" YourFile
add -posix on GNU sed
Upvotes: 2
Reputation: 41446
Using gnu awk
awk 'NR>1 {print RS substr($0,1,5)}' RS="MY-" file
MY-27125
MY-27132
MY-26565
MY-26097
MY-27129
MY-27211
MY-26565
MY-27175
MY-27147
MY-27159
MY-27149
MY-26747
MY-26945
MY-20811
MY-26889
Upvotes: 2
Reputation:
grep '^MY-' < in.txt | cut -b1-8
MY-27125
MY-27132
MY-26565
MY-26097
MY-27129
MY-27211
MY-27175
MY-27159
MY-26747
MY-20811
Upvotes: 1