I am looking for prepare string with file path and skip if path already exist by space separation. Because i need to loop and iterate for read file content as well. ex: i have list of file names in file like filePath1.txt filePath2.txt filepath3.txt in above want to add all file names in string and skip if file path name already in string. It will be helpful to iterate the string read file as well. thanks in advance... :)
Asked
Active
Viewed 102 times
0
-
kindly edit your question with 1) example content of filePath1.txt 2) script with prepare string before 3) what is passed to read loop 4) expected resulting prepare string after – alecxs Jul 03 '20 at 10:12
-
you may descripe what your real goal is, sure there are better solution than saving multiple file names in string – alecxs Jul 03 '20 at 10:14
-
@SreenivasPonnadi : How are you representing file names with embedded white space inside your string? And why are you going to use a string, and not an array, if you plan to iterate over it? – user1934428 Jul 03 '20 at 10:37
-
@alecxs : You can use various ways to approach this, but the OP did not mention what he is using in **his** strings; he just says _with space separation_. Hence, to discuss a solution, it would be helpful to know the exact syntax for his strings, for a start. – user1934428 Jul 03 '20 at 10:51
-
https://stackoverflow.com/a/37210472 – alecxs Jul 04 '20 at 00:22
1 Answers
1
I am doing like below to skip if var1 contains path. and getting result as expected now. echo ${var1} | grep --quiet "${filePath}" if [ $? = 1 ] then var1=$var1' '$filePath fi
Now var1 have list of files like - /foldr/subfoldr/tmp.properties many files with space seperated. I need to iterate each file and inside file each line value need to compare with /tmp/actualVal.properties. If it's different need to replace value in file from actualProperties

Sreenivas Ponnadi
- 109
- 1
- 8
-
-
hey apologies for confusing as new to bash.. My goal is 1.read list of file entries from one text file and add it one string (skip the entry if already exist in string) 2. Iterate each file from string read file content and replace the content string from another temp file, I mean file have properties if property value is wrong than need to replace from temp file. This question and answer is related to 1st point..looking 2nd to implement with bash. – Sreenivas Ponnadi Jul 03 '20 at 17:15
-
1use `while read` loop over list straight from file without concatenating file names into one string (see linked answer) remove duplicates with `cat filePath*.txt | sort | uniq -u` and pass into loop via process substitution. inside loop replace property value with `sed` for each file name (*"If it's different replace value"* is same like *replace always* - no need for comparison) – alecxs Jul 04 '20 at 00:39