Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

shell - extract content from patterns in File using sed

i am working on building and deploying artefact based on changed files in Github commit.

i am able to get changed files in latest commit in a json file and format is like below

common/modules/module1/one.txt
common/modules/module2/one.txt
common/modules/module1/api/two.txt

I am using GitHub Actions and want to extract list of modules which were changed in last commit, so in this case module1 and module2 should be my output.

modules name can be anything but the pattern would be /modules/ in file.

how can i extract these using shell ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Take the 3rd slash-separated field, then get the unique entries

... | awk -F/ '{print $3}' | sort -u

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...