Getting current folder name appended to all desired files
Hello everyone,
Just registered here, I'm kinda new to Unix
I've been trying to automate some processes with various Windows tools. I found that using unix scripts the result would be closest to my needs. So I installed Cygwin on Windows 7.
My folders and files are structured like this:
folder1
-file1_temp.txt
-file2_temp.txt
folder2
-file1_temp.txt
-file2_temp.txt
The desired outcome should look like this:
folder1
-file1_folder1.txt
-file2_folder1.txt
folder2
-file1_folder2.txt
-file2_folder2.txt
Now, here's what's bothering me:
1. I have a loop script for renaming files which contain the "temp" string for the current opened folder:
I want to automate the process of renaming files and replacing "temp" string in each file with the current folder name, but I'm failing to find a command which would automatically find the current folder name and put it in sed 's/temp/<FOLDER_NAME>/g'`.
2. I would also like to automate the above loop so that it could be applied to all folders (folder1, folder2, etc).
I have one other script with grep and sed commands which creates the mentioned above temp files. It looks like this:
Is there a way to join the above two scripts together, so that the script would execute the command in the following order for every subfolder in the main directory:
1. enter first subfolder and execute the grep and sed commands, creating the merged file in the current folder;
2. rename the merged file in the first subfolder to the name of the subfolder;
3. exit the first subfolder;
4. loop script with all subfolders until the end.
I was thinking of something like this:
But the above script creates the merged file in the main directory, not in the subfolder where it needs to be And if there's another folder, it copies it into the selected subfolder.
Doh.. it's getting complicated... I started this yesterday. Be easy on me
I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and
I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server
$ cat temp.txt
RTG*888*TD8*20180201~... (1 Reply)
Hi one of the output of the command is as below
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'
Resource List : <br>
*************************** 1. row ***************************<br>
... (2 Replies)
I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>"
So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (7 Replies)
I have multiple txt files which begin with the word "orders" in folder C:\source. I need to move the files to folder C:\dest and rename them to "process_<date>_<count>"
So for example , if there are 3 files ordersa.txt , ordersb.txt and ordersc.txt in C:\source , after running the script I want... (1 Reply)
Hello guys,
I am sure this has been asked before, but honestly, I cant find post talking about it.
Here is what I need:
- A tar file will be generated manually by user
- This tar file is then used within a bash shell script
My source folder structure is like this:
... (2 Replies)
How do I find files in current folder only?
We are on AIX 5.3, so maxdepth is not supported.
I tried to do this
find /dir1/dir2/dir3/dir4 -prune -type f
to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files.
Somehow the -prune option works for dir3 level... (7 Replies)
Hi gurus,
I have set of files in a directory
ex : test_file1.csv
test_file2.csv
test_file3.csv
my requirement is to copy these files into another directory but with date appended to the name :
like after copying the files should look like : test_file1_07072008.csv
... (7 Replies)
Alright, I am sure this is a laughable question, but I don't know so I am going to ask anyway.
I have a little script I am writing to take information from one source, recode it in a certain way, and print to files for each subject I have data for. This all works perfectly. I just want to put... (6 Replies)
How do I pack (using tar zcvf ?) the current folder inluding all files and folders ??
I need to be sure to get all files and folders/subfolders...
Later I will unpack into a new folder on a new server..
Appreciate any help.. (3 Replies)