0
1
ADD file ... in /
21.44 MB
2
CMD ["bash"]
0 B
3
ENV DEBIAN_FRONTEND=noninteractive
0 B
4
COPY file:6229791a987783682b536a308b0d287c470ec1bfa0be9b6b3471feab66706874 in /install.sh
925 B
5
/bin/sh -c /install.sh && rm
38.37 MB
6
ARG SPLUNK_FILENAME
0 B
7
ARG SPLUNK_BUILD_URL
0 B
8
ARG SPLUNK_DEFAULTS_URL
0 B
9
ENV SPLUNK_HOME=/opt/splunkforwarder SPLUNK_GROUP=splunk SPLUNK_USER=splunk
0 B
10
|1 SPLUNK_BUILD_URL=http://releases.splunk.com/dl/orangeswirl_builds/7.2.1-20181119-0400/splunkforwarder-7.2.1-be11b2c46e23-Linux-x86_64.tgz /bin/sh -c groupadd
23.32 MB
11
USER splunk
0 B
12
COPY dir:6e993b24f9f98057163ef8bd8c62e4861acd5bfa0b2053e0e38f2945df2a8e2a in /opt/ansible
20.04 KB
13
COPY multi:96216845d7aa8a7c7fe1625c00b24c9cf8c2077b7bfb6cd2170777135f01fa20 in /sbin/
2.92 KB
14
COPY multi:fb03ac2df458b42167388f14efe28124d79c80127da9acdba91b01e5ef99d67d in /tmp/
2.94 KB
15
EXPOSE 8088 8089 9997
0 B
16
VOLUME [/opt/splunkforwarder/etc /opt/splunkforwarder/var]
0 B
17
HEALTHCHECK &{["CMD-SHELL" "/sbin/checkstate.sh ||
0 B
18
ENTRYPOINT ["/sbin/entrypoint.sh"]
0 B
19
CMD ["start-service"]
0 B
Command

I have copied the dockerfile contentfrom dockerhub but it comes with line number and sizes, I want to create an awk control file to extract just the dockerfile content without the numbers or sizes. That is, I want to print 2nd,5th,8th,11th and so on lines. I can do it with bash scripting but I'm learning awk and want to do it that way.

Edit:

ADD file ... in /
CMD ["bash"]
ENV DEBIAN_FRONTEND=noninteractive
COPY file:6229791a987783682b536a308b0d287c470ec1bfa0be9b6b3471feab66706874 in /install.sh
/bin/sh -c /install.sh && rm
ARG SPLUNK_FILENAME
ARG SPLUNK_BUILD_URL
ARG SPLUNK_DEFAULTS_URL
ENV SPLUNK_HOME=/opt/splunkforwarder SPLUNK_GROUP=splunk SPLUNK_USER=splunk
|1 SPLUNK_BUILD_URL=http://releases.splunk.com/dl/orangeswirl_builds/7.2.1-20181119-0400/splunkforwarder-7.2.1-be11b2c46e23-Linux-x86_64.tgz /bin/sh -c groupadd
USER splunk
COPY dir:6e993b24f9f98057163ef8bd8c62e4861acd5bfa0b2053e0e38f2945df2a8e2a in /opt/ansible
COPY multi:96216845d7aa8a7c7fe1625c00b24c9cf8c2077b7bfb6cd2170777135f01fa20 in /sbin/
COPY multi:fb03ac2df458b42167388f14efe28124d79c80127da9acdba91b01e5ef99d67d in /tmp/
EXPOSE 8088 8089 9997
VOLUME [/opt/splunkforwarder/etc /opt/splunkforwarder/var]
HEALTHCHECK &{["CMD-SHELL" "/sbin/checkstate.sh ||
ENTRYPOINT ["/sbin/entrypoint.sh"]
CMD ["start-service"]
Command

this should be the final output.

I'm at

awk 'BEGIN{NR==2 print $0}{NR==5,NR==8,... print $0}' 

I'm not sure if we can sort in BEGIN block and how to use increment logic with NR varaible.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Kosmos Nagios
  • 311
  • 1
  • 2
  • 10
  • 1
    Could you please do your efforts in form of code in your question along with sample expected output in your question and let us know then. – RavinderSingh13 Jun 14 '20 at 05:44
  • 2
    hint: use modulus operator and special variable that has line number – Sundeep Jun 14 '20 at 05:45
  • 1
    here's another hint: https://stackoverflow.com/questions/9968916/print-every-nth-line-into-a-row-using-gawk – Sundeep Jun 14 '20 at 05:47
  • @Sundeep Yes, I know NR is the variable and every nth line is easier and not quite I'm looking for. – Kosmos Nagios Jun 14 '20 at 05:53
  • 2
    See Sundeep's [hint](https://stackoverflow.com/questions/62368803/print-nth-n3rd-n33rd-lines-using-awk?noredirect=1#comment110304442_62368803).. Start with second row and output every third row: `awk 'NR%3==2' file` – Cyrus Jun 14 '20 at 05:56
  • @Cyrus perfect, Can you add it to answers, so I can accept the answer. – Kosmos Nagios Jun 14 '20 at 05:58
  • 2
    @KosmosNagios: I closed your question with a link to a very similar question – Cyrus Jun 14 '20 at 05:59

0 Answers0