Problem Statement Find files using bash script In this section, you are going to write a script named findJane.sh within the scripts directory.
This script should catch all "jane" lines and store them in another text file called oldFiles.txt. You will complete the script using the command we practiced in earlier sections. Don't worry, we'll guide you throughout the whole process.
Navigate to /scripts directory and create a new file named findJane.sh.
Mycode
#!/bin/bash
>oldFiles.txt
files=$(grep " jane " ../data/list.txt | cut -d ' ' -f 3)
for i in $files:do
do if test -e ~/data/"$i"; then
echo "$i" >> OldFiles.txt;
else
echo "File doesn't exist"; fi
done
output now file does not exist file does not exist file does not exist it should not print nothing and cat oldFiles.txt should return all those files with name 'jane
Where i am coding wrong
Guide Create the text file oldFiles.txt and make sure it's empty. This oldFiles.txt file should save files with username "jane".
Now, search for all lines that contain the name "jane" and save the file names into a variable. Let's call this variable files, we will refer to it with that name later in the lab.
Since none of the files present in the file list.txt are available in the file system, check if file names present in files variable are actually present in the file system. To do this, we'll use the test command that we practiced in the previous section.
Now, iterate over the files variable and add a test expression within the loop. If the item within the files variable passes the test, add/append it to the file oldFiles.txt.
files, sofiles=$(...). Then, use the-lor--files-with-matchesoption to just get filenames. Even with that, if a filename has a space in it, theforloop will split the filename. (Person who put that space in the filename should be charged with conduct unbecoming of a human being.)files=$(grep...)line first.#!/bin/bashas the first line when you post there (you're missing a#char). If fixing the syntax errors doesn't solve your problem, then edit your Q with updated code so people aren't wasting time commenting on easy fixes. Include exact text of any error messages generated. Good luck.| cut ...stuff. Just use the-loption ongrep.