Printing only the file name after searching a pattern in the first line (using grep and head)
0
votes
6
answers
1661
views
So I'm a beginner and i have a project due next week. I have to print only the filename of the files that contain
#!/bin/bash
on the first line. So far I tried this
head -n 1 $filename | grep -l "pattern"
but when I execute it instead of the name of the files I receive
(standard input)
Like I said, I'm a beginner and so far I'm familiar with simple commands. So I would like to know where I f****** up and if there is a way of acheiving what I want without using harder commands like awk
.
for fis in find -perm -a+x -name "*.sh" -type f
do
head -n 1 $fis | grep -l "#!/bin/bash"
done
Asked by Laura
(1 rep)
May 21, 2020, 10:39 PM
Last activity: Nov 15, 2023, 07:10 PM
Last activity: Nov 15, 2023, 07:10 PM