Issue
I have a file that contains multiples informations, i'm trying to delete all the content of the file except a specific pattern that i want as a list.
/[csc]-[ALPHANUM of 4]-[ALPHANUM]-[ALPHANUM of 3]-[NUM of 8]/
The pattern always have csc
at the start but can be in the middle of the lines.
It has /
athe the start of the pattern and at the end sometimes (if this could help) but i just need what's between.
Example :
/csc-dbc1-repo01x-x11-20210101/
i tried to do something like this :
grep 'csc-[a-z0-9]{4}-[a-z0-9]-[0-9]{3}-[0-9]{8}' file1
But it returns nothing. Is there anyway i can have these patterns listed in the file.
Expected result :
csc-dbc1-repo01x-x11-20210301
csc-dvc1-rmco01x-x12-20220104
csc-cbc1-revehq1-A11-20210101
Extract of lines from the file containing a pattern :
"assets" : [ {
"downloadUrl" : "https://URL/repository/doc/v&/PROJECT/SUBP/csc-dbc1-repo01x-x11-20210301/DIR/DIR2",
"path" : "v&/PROJECT/SUBP/csc-dbc1-repo01x-x11-20210301/DIR/DIR2",
Solution
Using sed
$ sed -En 's/.*(csc-[[:alnum:]-]+).*/\1/p' input_file
csc-dbc1-repo01x-x11-20210301
csc-dbc1-repo01x-x11-20210301
Answered By - HatLess Answer Checked By - Marie Seifert (WPSolving Admin)