0

I have a file named DeployList.txt and it contains sample lines as below.

Database/test.sql
Tivoli/jobstr01.js
Tivoli/res01.res
Tivoli/job01.job
Datastage/test.dsx

I need to grep lines starting with "Tivoli/", but I would need the .res lines first, followed by the .job and finally the .js lines. Any other pattern would follow subsequently . So the output would look like...

Tivoli/res01.res
Tivoli/job01.job
Tivoli/jobstr01.js

So I am stuck till..

grep -e ^Tivoli/ DeployList.txt

And I don't want to create any further temporary files for this purpose.

4
  • what "other pattern" is involved here? do you mean 'Tivoli/somethingelse.extension"? or something besides "Tivoli"? Commented Jan 9, 2019 at 1:27
  • Is a perl answer acceptable? Commented Jan 9, 2019 at 1:39
  • I think a perl/awk script is more suitable for this kind of task. Commented Jan 9, 2019 at 3:10
  • @JeffSchaller : Yes. If there's a chance that Tivoli/somethingelse.extension exists, it should come last Commented Jan 9, 2019 at 4:02

1 Answer 1

1

You could do something like this, in GNU Awk > 4.0

gawk -F'[.]' '
  BEGIN{
    i["res"]=3; i["job"]=2; i["js"]=1; 
    PROCINFO["sorted_in"]="@val_num_desc"
  } 
  /^Tivoli/ {
    a[$0]=i[$2]
  } 
  END{
    for (x in a) print x
}' DeployList.txt 
Tivoli/res01.res
Tivoli/job01.job
Tivoli/jobstr01.js

The associative array i["res"]=3; i["job"]=2; i["js"]=1 defines a sort order for the extensions - other extensions will return 0 so will sort last.

0

You must log in to answer this question.