To start with, I know this way is quite not the right one, as often mentioned why shouldn't I parse the output of ls, but it is a part of my university project (so I could use sed and awk along).
I have to find files which names start with a given string. I stared with listing the current directory using ls:
ls -LR1
which gives me the example output:
.:
bin
etc
games
include
lib
man
sbin
share
src
./bin:
apt
gnome-help
highlight
mint-sha256sum
pastebin
search
szukaj
yelp
./etc:
./games:
./include:
./lib:
python2.7
python3.5
./lib/python2.7:
dist-packages
site-packages
./lib/python2.7/dist-packages:
./lib/python2.7/site-packages:
./lib/python3.5:
dist-packages
./lib/python3.5/dist-packages:
./man:
./sbin:
./share:
ca-certificates
emacs
fonts
man
sgml
xml
./share/ca-certificates:
./share/emacs:
site-lisp
./share/emacs/site-lisp:
./share/fonts:
./share/man:
./share/sgml:
declaration
dtd
entities
misc
stylesheet
./share/sgml/declaration:
./share/sgml/dtd:
./share/sgml/entities:
./share/sgml/misc:
./share/sgml/stylesheet:
./share/xml:
declaration
entities
misc
schema
./share/xml/declaration:
./share/xml/entities:
./share/xml/misc:
./share/xml/schema:
./src:
Now I want to use sed or possibly awk to get to get files with names starting with given string, lets say 'Do'. I would like to achieve something like this:
sed(orawk?) parses each line and searches for line that starts with'Do'- If there is a match, moves to previous line and searches for . (which is an indicator for relative path), if there's no match jumps to the line before and so on
- Prints the line as relative path:
.path/filename
Is it even possible to achive? Thank you for your help!
find . -name 'Do*'findexistence, however as stated in OP, I am required to usesedand/orawk.sedorawkare the correct tools for the job. Finding files isn't one of them.