scan and edit in bash

so assume I have a dozen files in local directory and half of them are .txt and I only want to scan these text files and go inside each of them and replace absolute paths (e.g. C:\blabla\more blahblah\myfile.txt) with just the name of that file (myfile.txt) and then go to next line and look if there are more paths to replace, and when done go to next text file. can someone please show me how to do this?

Can you show how your txt look like?
I wanted to know if the "C:\blabla\more blahblah\myfile.txt" is on separate line or on same line with other words, etc.

considering they are on separate lines....here is a piece of code...not tested though

find <local directory> -type f -name "*.txt" > all_text_files.dat

while read FILE_NAME
do
    cat $FILE_NAME | grep "C:\" > absolute_paths.dat
    
    while read PATH_FILE
    do
        INSIDE_FL_NME=`basename $PATH_FILE`
        
        cat $FILE_NAME | sed "s|$PATH_FILE|$INSIDE_FL_NME|g" > temp_file.dat
        
        cp temp_file.dat $FILE_NAME
        
    done < absolute_paths.dat
    
done < all_text_files.dat

corrected the code in the cp statement

file looks like this:

some line
comment1 C:\blabla\more blahblah\myfile1
comment2 C:\blabla\more blahblah\myfile2
some other line

and I need it to only show:

some line
comment1 myfile1
comment2 myfile2
some other line

---------- Post updated at 11:14 AM ---------- Previous update was at 10:57 AM ----------

I get this error:

syntax error at line 19: `end of file' unexpected

corrected the cp statement.
Also, use this for getting the second part

cat $FILE_NAME | grep "C:\" | awk '{print $2}' > absolute_paths.dat

I used both corrections and now I get:

line 11: unexpected EOF while looking for matching `"'
line 19: syntax error: unexpected end of file

small details!! :frowning: there was a "\" in the grep....must have been escaping the quote!

cat $FILE_NAME | grep "C:" | awk '{print $2}' > absolute_paths.dat

ah yes! it works fine with that change :slight_smile:
now it only needs to do the file editing I mentioned in the beginning and it's all done:

C:\blabla\more blahblah\myfile1

has to be replaced with:

myfile1

inside each line and each of the files.

---------- Post updated at 12:53 PM ---------- Previous update was at 12:24 PM ----------

I feel like maybe I didn't explain it clearly enough so sorry about that. All I needed is that the file content remains untouched except that absolute paths get reduced to just the file name they contain, which is now not happening as I see the original file being copied over as is. Thanks a lot for all your help so far!

---------- Post updated at 02:12 PM ---------- Previous update was at 12:53 PM ----------

I think sed is doing something wrong as it's not removing the path as it should.

---------- Post updated at 02:34 PM ---------- Previous update was at 02:12 PM ----------

nope it's not the sed it's the basename ! that line just copied the path as it is and then it pastes it over so obviously the final file remains unchanged :frowning: help?

---------- Post updated at 03:03 PM ---------- Previous update was at 02:34 PM ----------

is it possible a unix/linux system does not interpret correctly Windows paths as in the examples I provided? that could be a cause nothing is changed from the original file. in this case how can I tell my unix system that the Windows path is really a path and not a regular string?