Scenario :
A folder in Linux system. I want to loop through every .xls file in a folder.
This folder typically consists of various folders, various filetypes (.sh, .pl,.csv,...).
All I want to do is loop through all files in the root and execute a program only on .xls files.
xls2csv is the program i need to run
for example:
i have 300 directories at /home/ftp_account/user1 up to user300 w/c contains .xls files in every folder,i want to convert all .xls files then move the converted files to /home/ftp_account/user1/converted
take note: converted files for user1 will go to /home/ftp_users/user1/converted
files for user2 will go to /home_ftp_users/user2/converted
files for user3 will go to /home_ftp_users/user3/converted
etc....
Please help!
Thanks guys :)
#!/bin/bash
for dir in /home/ftp_users/user{1..300}; do
for file in $dir/*.xls; do
fn=$(basename ${file})
fn=${fn%.*}
mkdir -p $dir/converted
xls2csv $file > $dir/converted/${fn}.csv
done
done
Related
I have a bunch of directories which were organized on date.
e.g.
the following directory are sequential dates.
/200001 ..../200201 /200202 /200203...../202209
There are tons of files in those directories and i'd like to move those files with name "*.csv" and the directory is from 200501 to 202209 to /tmp directory.
I know the following command is wrong, but it shows what i'd like to do
mv /{200501..202209}/*.csv /tmp
How can I do it by writing a shell script?
Sorry i am very new to os linux.
Hi everyone this is saikrishna. I need some help in linux shell scripts. I need to open the different types of files like mp3,mp4,jpg...etc and other extensions are existing in the same folder. I had tried "gnome" code for this but it opens only one file i needed to open all the files one after the other.
is it possible in linux.need help for it
You can list multiple files using ls and then use while to open them one by one:
ls *.mp3 | while read -r file; do xdg-open "$file"; done
see this answer for more details.
I have several files in a folder with extension .img and I have only one file with extension data.txt
What I need is to copy data.txt and rename it as the names of the .img files.
For instance for the first file in my folder:
`Meaurmen_2154_data.img` >>> copy data.txt >>> rename it Meaurmen_2154_data.txt
Now I have :
Meaurmen_2154_data.img
Meaurmen_2154_data.txt ## the content is the same as data.txt
and do the same for all other files. The content of he text files will be the same for all files just we change the name according to the .img files in my folder.
Run this script
#!/bin/bash
imageFiles=( *.img );
for i in ${imageFiles[*]}
do
withoutExtension=${i%.img};
cp data.txt "$withoutExtension.txt";
done
inside the relevant directory and it will do it for you.
Try
for i in *.img; do cp data.txt $i.txt; done
rename 's/.img.txt/.txt/' *.img.txt
In some distro's rename is different, requiring
rename .img.txt .txt *.img.txt
As always, you might find yourself in need of installing additional packages.
I have 500 .txt files and I need to merge them into 1 .txt file. I could do this manually by hand but it would take a long time. I'm wondering if there's an easier way via command line? I would need a new line character between each .txt file's contents in the end text file. I'm running Windows 7 but also have Cygwin installed.
You may place all the txt files into a folder.
Open Window CMD
Move to that folder and Run this command
for %f in (*.txt) do type "%f" >> output.txt
All the files will be merged into output.txt
Im amateur in script shell so i need help for shell cripting for my issue :
i have 2 directory inside this path /home/backup :
CSC
DFG
and each folder (CSC & DFG) have a these dir inside : weekly and monthly
and i want to copy all files and packing into 1 file .tar inside weekly dir > into monthly dir
so my question :
hows the script for this my issue?
Thanks
I'm not sure I understand your question, but if you want to create a tar file, here is the command (with verbose):
tar -cvf backup.tar /home/backup/*
and then if you need to compress it, which I assume you want to do:
gzip backup.tar