by doing the following command in the folder
ls -d */ | cut -f1 -d'/'
I get entries like:
env1
env2
env3
env4
how I can use cat/grep
or yq/jq
or any other alternative command(s) instead of the above command?
by doing the following command in the folder
ls -d */ | cut -f1 -d'/'
I get entries like:
env1
env2
env3
env4
how I can use cat/grep
or yq/jq
or any other alternative command(s) instead of the above command?
for dir in */; do
echo "${dir%/}"
done
There are several options. You can use the tree command with the options:
# d: list only directories
# i: no print of indention line
# L: max display depth of the directory tree
tree -di -L 1 "$(pwd)"
Or you can also use the grep command to get the directories and the command awk:
# F: input field separator
# $9: print the ninth column of the output
ls -l | grep "^d" | awk -F" " '{print $9}'
Or you can use the sed command to remove the slash:
# structure: s|regexp|replacement|flags
# g: apply the replacement to all matches to the regexp, not just the first
ls -d */ | sed 's|[/]||g'
I found this solutions in this post.