1

I have 2 folder - folder1 and folder2.

Im in folder1 and need to execute a shellscript that will search for all the csv files in folder2..

The current script check *.csv in the current folder..how to point to folder2?

for file in *.csv
do
  split -l 50000 -d -a 4  "$file" "$file"
done
5

Assuming both folder1 and folder2 are under parent folder,

parent
   folder1
   folder2

You can rephrase your for loop as,

for file in ../folder2/*.csv

As a general rule, you can always give absolute paths to such loops:

for file in /home/username/parent/folder2/*.csv
do
    split -l 50000 -d -a 4  "$file" "$file"
done

The loop above will work irrespective of which directory you happen to be in.

3

You can use pushd and popd whenever you need to change directory for some operations and then change it back to the original.

pushd /path/to/folder2
for file in *.csv
do
  split -l 50000 -d -a 4  "$file" "$file"
done
popd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.