Looping through contents of a file and finding it in different directory The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsUnderstanding “IFS= read -r line”How can I cat the contents of files found using find into a single file?What is wrong with my init.d script [Segmentation fault]What is the best way to delete files & folders in a directory excluding the contents of one folder?how do I extract the SubDir name 4 deep & put into a Var 4 later use?Looping through lines in file using bash and passing to variable. Resulting variable is not the same value as file, why?Preform operation in bash only if a variable is less than a second variableDynamic Functionfinding a way to wait for an unknown named file to appear in a directory and then doing something with itScript not correctly printing the correct elements of the arraymove file after validation
Did the new image of black hole confirm the general theory of relativity?
Are spiders unable to hurt humans, especially very small spiders?
Make it rain characters
Circular reasoning in L'Hopital's rule
Why not take a picture of a closer black hole?
should truth entail possible truth
How to make Illustrator type tool selection automatically adapt with text length
60's-70's movie: home appliances revolting against the owners
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
How did the crowd guess the pentatonic scale in Bobby McFerrin's presentation?
What was the last x86 CPU that did not have the x87 floating-point unit built in?
What is the padding with red substance inside of steak packaging?
Simulating Exploding Dice
Is every episode of "Where are my Pants?" identical?
"... to apply for a visa" or "... and applied for a visa"?
Student Loan from years ago pops up and is taking my salary
Can a flute soloist sit?
Why can I use a list index as an indexing variable in a for loop?
Word to describe a time interval
What do I do when my TA workload is more than expected?
Match Roman Numerals
Define a list range inside a list
Am I ethically obligated to go into work on an off day if the reason is sudden?
Mortgage adviser recommends a longer term than necessary combined with overpayments
Looping through contents of a file and finding it in different directory
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election ResultsUnderstanding “IFS= read -r line”How can I cat the contents of files found using find into a single file?What is wrong with my init.d script [Segmentation fault]What is the best way to delete files & folders in a directory excluding the contents of one folder?how do I extract the SubDir name 4 deep & put into a Var 4 later use?Looping through lines in file using bash and passing to variable. Resulting variable is not the same value as file, why?Preform operation in bash only if a variable is less than a second variableDynamic Functionfinding a way to wait for an unknown named file to appear in a directory and then doing something with itScript not correctly printing the correct elements of the arraymove file after validation
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need to compare the contents of a file located in dir A with actual files in different directory. ex- directory A has a file test.txt , Item mentioned in test.txt and not present in directory B should be highlighted. im doing something like this but not working.. it is only searching last word from the file test.txt
#!/bin/sh
IFS=$'n' dirA=$1 dirB=$2
for x in $(cat < "$1"); do base_name="$x##/"
set -- "$dirB"/"$base_name"*
if [ -e "$1" ]; then
for y; do
echo "$base_name found in B as $y##*/" done
else
echo "$x not found in B" fi done.
shell-script
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I need to compare the contents of a file located in dir A with actual files in different directory. ex- directory A has a file test.txt , Item mentioned in test.txt and not present in directory B should be highlighted. im doing something like this but not working.. it is only searching last word from the file test.txt
#!/bin/sh
IFS=$'n' dirA=$1 dirB=$2
for x in $(cat < "$1"); do base_name="$x##/"
set -- "$dirB"/"$base_name"*
if [ -e "$1" ]; then
for y; do
echo "$base_name found in B as $y##*/" done
else
echo "$x not found in B" fi done.
shell-script
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I tested this program in my cygwin environment. It works well! Maybe it's bash setting problem?
– JinChin
yesterday
@JinChin Notice that the user is not executing this withbash, and that the code does not include anything that is specific to that shell.
– Kusalananda♦
yesterday
add a comment |
I need to compare the contents of a file located in dir A with actual files in different directory. ex- directory A has a file test.txt , Item mentioned in test.txt and not present in directory B should be highlighted. im doing something like this but not working.. it is only searching last word from the file test.txt
#!/bin/sh
IFS=$'n' dirA=$1 dirB=$2
for x in $(cat < "$1"); do base_name="$x##/"
set -- "$dirB"/"$base_name"*
if [ -e "$1" ]; then
for y; do
echo "$base_name found in B as $y##*/" done
else
echo "$x not found in B" fi done.
shell-script
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I need to compare the contents of a file located in dir A with actual files in different directory. ex- directory A has a file test.txt , Item mentioned in test.txt and not present in directory B should be highlighted. im doing something like this but not working.. it is only searching last word from the file test.txt
#!/bin/sh
IFS=$'n' dirA=$1 dirB=$2
for x in $(cat < "$1"); do base_name="$x##/"
set -- "$dirB"/"$base_name"*
if [ -e "$1" ]; then
for y; do
echo "$base_name found in B as $y##*/" done
else
echo "$x not found in B" fi done.
shell-script
shell-script
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
Kusalananda♦
141k17263439
141k17263439
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked yesterday
Roopak MurtyRoopak Murty
1
1
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Roopak Murty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I tested this program in my cygwin environment. It works well! Maybe it's bash setting problem?
– JinChin
yesterday
@JinChin Notice that the user is not executing this withbash, and that the code does not include anything that is specific to that shell.
– Kusalananda♦
yesterday
add a comment |
I tested this program in my cygwin environment. It works well! Maybe it's bash setting problem?
– JinChin
yesterday
@JinChin Notice that the user is not executing this withbash, and that the code does not include anything that is specific to that shell.
– Kusalananda♦
yesterday
I tested this program in my cygwin environment. It works well! Maybe it's bash setting problem?
– JinChin
yesterday
I tested this program in my cygwin environment. It works well! Maybe it's bash setting problem?
– JinChin
yesterday
@JinChin Notice that the user is not executing this with
bash, and that the code does not include anything that is specific to that shell.– Kusalananda♦
yesterday
@JinChin Notice that the user is not executing this with
bash, and that the code does not include anything that is specific to that shell.– Kusalananda♦
yesterday
add a comment |
2 Answers
2
active
oldest
votes
Using diff may do the trick
diff -crs Dir1 Dir2
It will show you if the files are existing, same or different
with a grep on filename might be what you are looking for
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
Ok, sorry, may be read a bit too fast. In that case you could usediff -crs ./file /path_to_file/DIrIt also show you where are the differences
– PhLinuX
yesterday
add a comment |
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$name"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
This script takes a manifest file as its first command line argument, and some directory path as its second argument.
It reads lines from the manifest and tests to see if the pathnames corresponding to those lines exists under the given directory.
Would you only want to test the base name of each name read from the file, then use
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$( basename "$name" )"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
Related:
- Understanding "IFS= read -r line"
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that/Users/dir2/adoes not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.
– Kusalananda♦
yesterday
@RoopakMurty Are you saying that/Users/dir2/aexists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.
– Kusalananda♦
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
|
show 3 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Roopak Murty is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511858%2flooping-through-contents-of-a-file-and-finding-it-in-different-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using diff may do the trick
diff -crs Dir1 Dir2
It will show you if the files are existing, same or different
with a grep on filename might be what you are looking for
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
Ok, sorry, may be read a bit too fast. In that case you could usediff -crs ./file /path_to_file/DIrIt also show you where are the differences
– PhLinuX
yesterday
add a comment |
Using diff may do the trick
diff -crs Dir1 Dir2
It will show you if the files are existing, same or different
with a grep on filename might be what you are looking for
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
Ok, sorry, may be read a bit too fast. In that case you could usediff -crs ./file /path_to_file/DIrIt also show you where are the differences
– PhLinuX
yesterday
add a comment |
Using diff may do the trick
diff -crs Dir1 Dir2
It will show you if the files are existing, same or different
with a grep on filename might be what you are looking for
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Using diff may do the trick
diff -crs Dir1 Dir2
It will show you if the files are existing, same or different
with a grep on filename might be what you are looking for
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered yesterday
PhLinuXPhLinuX
365
365
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
PhLinuX is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
Ok, sorry, may be read a bit too fast. In that case you could usediff -crs ./file /path_to_file/DIrIt also show you where are the differences
– PhLinuX
yesterday
add a comment |
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
Ok, sorry, may be read a bit too fast. In that case you could usediff -crs ./file /path_to_file/DIrIt also show you where are the differences
– PhLinuX
yesterday
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
The idea seems to be to verify some sort of manifest over files that are supposed to exist, not to compare two directories.
– Kusalananda♦
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
i want to check file contents in another directory. example file 1 (located in /user/home) has a,b,c so i need to check if a,b,c is present as files in different folder (/etc)
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
@Kusalananda , yes that is correct, l'm looking for manifest over files that are supposed to exist
– Roopak Murty
yesterday
Ok, sorry, may be read a bit too fast. In that case you could use
diff -crs ./file /path_to_file/DIr It also show you where are the differences– PhLinuX
yesterday
Ok, sorry, may be read a bit too fast. In that case you could use
diff -crs ./file /path_to_file/DIr It also show you where are the differences– PhLinuX
yesterday
add a comment |
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$name"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
This script takes a manifest file as its first command line argument, and some directory path as its second argument.
It reads lines from the manifest and tests to see if the pathnames corresponding to those lines exists under the given directory.
Would you only want to test the base name of each name read from the file, then use
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$( basename "$name" )"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
Related:
- Understanding "IFS= read -r line"
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that/Users/dir2/adoes not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.
– Kusalananda♦
yesterday
@RoopakMurty Are you saying that/Users/dir2/aexists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.
– Kusalananda♦
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
|
show 3 more comments
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$name"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
This script takes a manifest file as its first command line argument, and some directory path as its second argument.
It reads lines from the manifest and tests to see if the pathnames corresponding to those lines exists under the given directory.
Would you only want to test the base name of each name read from the file, then use
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$( basename "$name" )"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
Related:
- Understanding "IFS= read -r line"
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that/Users/dir2/adoes not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.
– Kusalananda♦
yesterday
@RoopakMurty Are you saying that/Users/dir2/aexists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.
– Kusalananda♦
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
|
show 3 more comments
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$name"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
This script takes a manifest file as its first command line argument, and some directory path as its second argument.
It reads lines from the manifest and tests to see if the pathnames corresponding to those lines exists under the given directory.
Would you only want to test the base name of each name read from the file, then use
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$( basename "$name" )"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
Related:
- Understanding "IFS= read -r line"
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$name"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
This script takes a manifest file as its first command line argument, and some directory path as its second argument.
It reads lines from the manifest and tests to see if the pathnames corresponding to those lines exists under the given directory.
Would you only want to test the base name of each name read from the file, then use
#!/bin/sh
manifest=$1
topdir=$2
while IFS= read -r name; do
pathname="$topdir/$( basename "$name" )"
if [ -e "$pathname" ]; then
printf 'Found: %sn' "$pathname" >&2
else
printf 'Not found: %sn' "$pathname" >&2
fi
done <"$manifest"
Related:
- Understanding "IFS= read -r line"
answered yesterday
Kusalananda♦Kusalananda
141k17263439
141k17263439
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that/Users/dir2/adoes not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.
– Kusalananda♦
yesterday
@RoopakMurty Are you saying that/Users/dir2/aexists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.
– Kusalananda♦
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
|
show 3 more comments
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that/Users/dir2/adoes not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.
– Kusalananda♦
yesterday
@RoopakMurty Are you saying that/Users/dir2/aexists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.
– Kusalananda♦
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
what is pathname="$topdir/$( basename "$name" )" in the above code.. it is showing opposite result Not found:/Users/dir2/a Not found: /Users/dir2/b Not found: /Users/dir2/c , but a ,b, c are present in dir2 as txt files.
– Roopak Murty
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that
/Users/dir2/a does not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.– Kusalananda♦
yesterday
@RoopakMurty The line creates a new value that is the directory path that is was given followed by the base name of the line read from the file. If the script says that
/Users/dir2/a does not exist, well, then that pathname does not exist. The type of file is not taken into consideration. If you could describe a bit more, then maybe I would understand what you mean.– Kusalananda♦
yesterday
@RoopakMurty Are you saying that
/Users/dir2/a exists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.– Kusalananda♦
yesterday
@RoopakMurty Are you saying that
/Users/dir2/a exists? Do you have spaces at the end of the lines in the file that you pass to the script? In that case, delete those spaces.– Kusalananda♦
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
yes a is a text file under /Users/dir2 that exists, actually I'm using git bash in windows to run this script, is this a problem ?
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
installed cygwin, and it works now. :-)
– Roopak Murty
yesterday
|
show 3 more comments
Roopak Murty is a new contributor. Be nice, and check out our Code of Conduct.
Roopak Murty is a new contributor. Be nice, and check out our Code of Conduct.
Roopak Murty is a new contributor. Be nice, and check out our Code of Conduct.
Roopak Murty is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511858%2flooping-through-contents-of-a-file-and-finding-it-in-different-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-shell-script
I tested this program in my cygwin environment. It works well! Maybe it's bash setting problem?
– JinChin
yesterday
@JinChin Notice that the user is not executing this with
bash, and that the code does not include anything that is specific to that shell.– Kusalananda♦
yesterday