Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an awk script that counts the average of rows from every file from a given directory and its subdirectories and I have to print the filename and the average from a file like this example.c : 5. So I have filenames like this ../labor1/munka/hazik_pagi4188/hazik/c_prog/lab1/fork2.c and I want to get like this fork2.c (I have different length file names with path)


What I have tried:

sub("[^\/]*$","")
I always get this error message
awk: warning: escape sequence `\/' treated as plain `/'
Posted
Comments
Peter_in_2780 8-Jun-22 21:31pm    
Hint: man basename
Richard MacCutchan 9-Jun-22 5:39am    
You do not need to escape a forward slash in that position. You can select the final part of the string by using the FS character to split the string into fields, and the NF variable to know how many parts there are.
Member 10601191 16-Jul-23 20:35pm    
could you share your awk script?, there may well be better alternatives to parsing them a filename in awk (basename as hinted), likewise counting lines in a file - there's already a utility to do that for you (the wc utility)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900