Answer the question
In order to leave comments, you need to log in
How to correctly replace paths in filenames?
Good people, help me solve such a problem, because. I don't understand bash at all.
I have a directory in which the photo, I found a script that writes the names of each to the file on a new line. They are obtained with the paths of my PC, I need to replace these paths with others and add array characters at the beginning and at the end.
Those. there is a list:
старый путь/файл_1.jpg
старый путь/файл_2.jpg
var arrIm = [
'новый путь/файл_1.jpg'
'новый путь/файл_2.jpg'
];
Answer the question
In order to leave comments, you need to log in
cat fileOldPath.txt | awk -F/ 'BEGIN{print "var arrIm = ["}{print "'\''новый путь/"$NF"'\''"}END{print "];"}' > fileNewPath.txt
Senseich
here is your example with corrected errors
the only thing that I did not analyze is localized directory names ..
remove Russian on the way - name it in English letters
#!/bin/bash
FILE="/tmp/file2.txt"
B='var arrIm = ['
L=$(cat $FILE | sed -e "s/\\(..*\\)/'\\1'/g" | sed -e 's|C:\\Users\\SEN\\Desktop\\777\\|https://ohiyo.ru/uploads/posts/|g')
E="
];"
echo "$B$L$E"
cat $FILE
C:\Users\SEN\Desktop\777\XXX.TXT
./a.sh
var arrIm = ['https://ohiyo.ru/uploads/posts/XXX.TXT'
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question