I'm doing an assignment for school, and while we have not yet learned regular expressions, my teacher would like us to use AWK to append text to certain lines in a file.
What we've had to do is creating a listing of all links and directories in the /etc folder and place them in a text file. From this, we were to cut the first field (Permissions) and the ninth field (filename) and create another text file.
Now the part that I'm struggling with is this and I'm not sure if I should be using sed or awk. We're supposed to ADD the text "DIR" to the beginning of any line that is a directory, and "LNK" to any that is a link, like so:
Obviously, I realize that the first character in the permissions denotes what sort of file it is, hence when I created my text file I used
ls -l | grep "^d" > file.txt
ls -l | grep "^l" >> file.txt
I'd like to learn how to properly do this, but struggling through pages on the internet hasn't been helping, nor has the --help command. Therefore, while I would like the answer, I'd also like to know what the heck I'm doing
For example, I know I could delete lines with regex using
d/[STUFF I WANT TO DELETE]/g (To get rid of all occurences)
and I can substitute using s/foo/bar
But I'm unaware of anyway to ADD text upon certain occurences, let alone two different circumstances.