0

I am using the following ssh command to get a list of ids. Now I want to

  1. get only ids greater than a given number in the list of ids; let's say "231219" in this case. How can I incorporate that?

  2. I have a local file "ids_ignore.txt"; anyid we put in this list should be ignored by the command..

Can awk or cut do the above?

ssh -p 29418 company.com gerrit query --commit-message --files --current-patch-set \
    status:open project:platform/code branch:master |
grep refs | cut -f4 -d'/'

OUTPUT:-

231222
231221
231220
231219
230084
229092
228673
228635
227877
227759
226138
226118
225817
225815
225246
223554
223527
223452
223447
226137
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user1934146
  • 2,905
  • 10
  • 25
  • 25

2 Answers2

1
... | awk '$1 > max' max=8888 | grep -v -F -f ids_ignore.txt

Or, if you want to do it all with awk:

 ... | awk 'NR==FNR{ no[$1]++ } 
        NR!=FNR && $1 > max && ! no[$1]' max=NNN ids_ignore.txt -
William Pursell
  • 204,365
  • 48
  • 270
  • 300
0

cut cannot do numeric comparison on the input fields, it's just a simple field extraction tool. awk can do the work of grep and cut:

ssh -p 29418 company.com gerrit ... |
awk -F/ -v min=231219 '
    NR == FNR {ignore[$1]; next} 
    /refs/ && $4>min && !($4 in ignore) {print $4}
' ids_ignore.txt -

The trailing - is important at the end of the awk command: it tells awk to read from stdin after it reads the ids_ignore file.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352