Remove all parent directories from a list of paths
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a bash command that lists the directories in HDFS beginning with '/random'.
It goes as follows:
hdfs dfs -ls -R /random | grep '^d' | awk 'print $NF'
It generates the following output:
/random/custom
/random/custom/hive
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
I would like to modify my command so that only the full directory path is listed, as follows:
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
How would you do it?
text-processing
New contributor
add a comment |Â
up vote
1
down vote
favorite
I have a bash command that lists the directories in HDFS beginning with '/random'.
It goes as follows:
hdfs dfs -ls -R /random | grep '^d' | awk 'print $NF'
It generates the following output:
/random/custom
/random/custom/hive
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
I would like to modify my command so that only the full directory path is listed, as follows:
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
How would you do it?
text-processing
New contributor
"I would like to modify my command so that only the full directory path is listed." What do you mean by this? Do you mean that only/random/custom/hive/jars
should be output (assumingjars
is a directory)? Do you mean that only the path to the/random/custom
directory should be listed? The full directory path to which location?
â code_dredd
4 hours ago
Also, did you try anything? If so, what was it?
â code_dredd
4 hours ago
Hi, I updated my post to answer your question. I have not tried anything yet. I am looking into awk, sed and grep as options.
â user316697
4 hours ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a bash command that lists the directories in HDFS beginning with '/random'.
It goes as follows:
hdfs dfs -ls -R /random | grep '^d' | awk 'print $NF'
It generates the following output:
/random/custom
/random/custom/hive
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
I would like to modify my command so that only the full directory path is listed, as follows:
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
How would you do it?
text-processing
New contributor
I have a bash command that lists the directories in HDFS beginning with '/random'.
It goes as follows:
hdfs dfs -ls -R /random | grep '^d' | awk 'print $NF'
It generates the following output:
/random/custom
/random/custom/hive
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
I would like to modify my command so that only the full directory path is listed, as follows:
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
How would you do it?
text-processing
text-processing
New contributor
New contributor
edited 2 mins ago
don_crissti
48k15126155
48k15126155
New contributor
asked 4 hours ago
user316697
62
62
New contributor
New contributor
"I would like to modify my command so that only the full directory path is listed." What do you mean by this? Do you mean that only/random/custom/hive/jars
should be output (assumingjars
is a directory)? Do you mean that only the path to the/random/custom
directory should be listed? The full directory path to which location?
â code_dredd
4 hours ago
Also, did you try anything? If so, what was it?
â code_dredd
4 hours ago
Hi, I updated my post to answer your question. I have not tried anything yet. I am looking into awk, sed and grep as options.
â user316697
4 hours ago
add a comment |Â
"I would like to modify my command so that only the full directory path is listed." What do you mean by this? Do you mean that only/random/custom/hive/jars
should be output (assumingjars
is a directory)? Do you mean that only the path to the/random/custom
directory should be listed? The full directory path to which location?
â code_dredd
4 hours ago
Also, did you try anything? If so, what was it?
â code_dredd
4 hours ago
Hi, I updated my post to answer your question. I have not tried anything yet. I am looking into awk, sed and grep as options.
â user316697
4 hours ago
"I would like to modify my command so that only the full directory path is listed." What do you mean by this? Do you mean that only
/random/custom/hive/jars
should be output (assuming jars
is a directory)? Do you mean that only the path to the /random/custom
directory should be listed? The full directory path to which location?â code_dredd
4 hours ago
"I would like to modify my command so that only the full directory path is listed." What do you mean by this? Do you mean that only
/random/custom/hive/jars
should be output (assuming jars
is a directory)? Do you mean that only the path to the /random/custom
directory should be listed? The full directory path to which location?â code_dredd
4 hours ago
Also, did you try anything? If so, what was it?
â code_dredd
4 hours ago
Also, did you try anything? If so, what was it?
â code_dredd
4 hours ago
Hi, I updated my post to answer your question. I have not tried anything yet. I am looking into awk, sed and grep as options.
â user316697
4 hours ago
Hi, I updated my post to answer your question. I have not tried anything yet. I am looking into awk, sed and grep as options.
â user316697
4 hours ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
You're looking to printing non-directory files only? Try piping your result through
awk -F/ 'NF <= OLDNF print LAST; OLDNF = NF; LAST = $0 END print LAST'
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
It looks for "growing depth" of the path read, and prints if that shrank (going back in dir depth) or stays equal (file on same hierarchy level).
lines need to be feed to awk with sorted and this will fail if you had a lines like/c/d
n/e/f/c
n/a/b
. since you are checking the number of fields
â sddgob
2 hours ago
add a comment |Â
up vote
0
down vote
Another awk
approach which is based on matching current line against the previous line. and you must sort the input first.
... |sort | awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print '
Input:
/random/custom
/c/d
/e/f/c
/a/b
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
Output:
$ awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print ' <(sort infile)
/a/b
/c/d
/e/f/c
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
/random/custom/hive/jars
add a comment |Â
up vote
0
down vote
With modern sed
s (and assuming sorted input):
sed -E '$!N;/(.+)n1/!P;D' infile
If your sed
is anticuado try:
sed '$!N;/(.1,)n1/!P;D' infile
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You're looking to printing non-directory files only? Try piping your result through
awk -F/ 'NF <= OLDNF print LAST; OLDNF = NF; LAST = $0 END print LAST'
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
It looks for "growing depth" of the path read, and prints if that shrank (going back in dir depth) or stays equal (file on same hierarchy level).
lines need to be feed to awk with sorted and this will fail if you had a lines like/c/d
n/e/f/c
n/a/b
. since you are checking the number of fields
â sddgob
2 hours ago
add a comment |Â
up vote
1
down vote
You're looking to printing non-directory files only? Try piping your result through
awk -F/ 'NF <= OLDNF print LAST; OLDNF = NF; LAST = $0 END print LAST'
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
It looks for "growing depth" of the path read, and prints if that shrank (going back in dir depth) or stays equal (file on same hierarchy level).
lines need to be feed to awk with sorted and this will fail if you had a lines like/c/d
n/e/f/c
n/a/b
. since you are checking the number of fields
â sddgob
2 hours ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You're looking to printing non-directory files only? Try piping your result through
awk -F/ 'NF <= OLDNF print LAST; OLDNF = NF; LAST = $0 END print LAST'
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
It looks for "growing depth" of the path read, and prints if that shrank (going back in dir depth) or stays equal (file on same hierarchy level).
You're looking to printing non-directory files only? Try piping your result through
awk -F/ 'NF <= OLDNF print LAST; OLDNF = NF; LAST = $0 END print LAST'
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
It looks for "growing depth" of the path read, and prints if that shrank (going back in dir depth) or stays equal (file on same hierarchy level).
answered 3 hours ago
RudiC
2,201110
2,201110
lines need to be feed to awk with sorted and this will fail if you had a lines like/c/d
n/e/f/c
n/a/b
. since you are checking the number of fields
â sddgob
2 hours ago
add a comment |Â
lines need to be feed to awk with sorted and this will fail if you had a lines like/c/d
n/e/f/c
n/a/b
. since you are checking the number of fields
â sddgob
2 hours ago
lines need to be feed to awk with sorted and this will fail if you had a lines like
/c/d
n/e/f/c
n/a/b
. since you are checking the number of fieldsâ sddgob
2 hours ago
lines need to be feed to awk with sorted and this will fail if you had a lines like
/c/d
n/e/f/c
n/a/b
. since you are checking the number of fieldsâ sddgob
2 hours ago
add a comment |Â
up vote
0
down vote
Another awk
approach which is based on matching current line against the previous line. and you must sort the input first.
... |sort | awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print '
Input:
/random/custom
/c/d
/e/f/c
/a/b
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
Output:
$ awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print ' <(sort infile)
/a/b
/c/d
/e/f/c
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
/random/custom/hive/jars
add a comment |Â
up vote
0
down vote
Another awk
approach which is based on matching current line against the previous line. and you must sort the input first.
... |sort | awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print '
Input:
/random/custom
/c/d
/e/f/c
/a/b
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
Output:
$ awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print ' <(sort infile)
/a/b
/c/d
/e/f/c
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
/random/custom/hive/jars
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Another awk
approach which is based on matching current line against the previous line. and you must sort the input first.
... |sort | awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print '
Input:
/random/custom
/c/d
/e/f/c
/a/b
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
Output:
$ awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print ' <(sort infile)
/a/b
/c/d
/e/f/c
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
/random/custom/hive/jars
Another awk
approach which is based on matching current line against the previous line. and you must sort the input first.
... |sort | awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print '
Input:
/random/custom
/c/d
/e/f/c
/a/b
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
Output:
$ awk '$0 ~ pre pre=$0; next preprint pre pre=$0 END print ' <(sort infile)
/a/b
/c/d
/e/f/c
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
/random/custom/hive/jars
answered 2 hours ago
sddgob
16.2k102564
16.2k102564
add a comment |Â
add a comment |Â
up vote
0
down vote
With modern sed
s (and assuming sorted input):
sed -E '$!N;/(.+)n1/!P;D' infile
If your sed
is anticuado try:
sed '$!N;/(.1,)n1/!P;D' infile
add a comment |Â
up vote
0
down vote
With modern sed
s (and assuming sorted input):
sed -E '$!N;/(.+)n1/!P;D' infile
If your sed
is anticuado try:
sed '$!N;/(.1,)n1/!P;D' infile
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With modern sed
s (and assuming sorted input):
sed -E '$!N;/(.+)n1/!P;D' infile
If your sed
is anticuado try:
sed '$!N;/(.1,)n1/!P;D' infile
With modern sed
s (and assuming sorted input):
sed -E '$!N;/(.+)n1/!P;D' infile
If your sed
is anticuado try:
sed '$!N;/(.1,)n1/!P;D' infile
answered 4 mins ago
don_crissti
48k15126155
48k15126155
add a comment |Â
add a comment |Â
user316697 is a new contributor. Be nice, and check out our Code of Conduct.
user316697 is a new contributor. Be nice, and check out our Code of Conduct.
user316697 is a new contributor. Be nice, and check out our Code of Conduct.
user316697 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476577%2fremove-all-parent-directories-from-a-list-of-paths%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
"I would like to modify my command so that only the full directory path is listed." What do you mean by this? Do you mean that only
/random/custom/hive/jars
should be output (assumingjars
is a directory)? Do you mean that only the path to the/random/custom
directory should be listed? The full directory path to which location?â code_dredd
4 hours ago
Also, did you try anything? If so, what was it?
â code_dredd
4 hours ago
Hi, I updated my post to answer your question. I have not tried anything yet. I am looking into awk, sed and grep as options.
â user316697
4 hours ago