I am running ubuntu and I have little experience with sed and awk.
I would like to rename files with the following:
ITIS50V_PHYS_LANDFORM_ARTIFIC_EXP_Areal_2014_09.shp
ITIS50V_LCLU_LANDCOVER_EXP_2014_03.dbf
ITIS50V_CULT_INDUSTRIAL_EXP_Linear_2014_02.shx
I would like to rename them to :
ITIS50V_PHYS_LANDFORM_ARTIFIC.shp
ITIS50V_LCLU_LANDCOVER.dbf
ITIS50V_CULT_INDUSTRIAL.shx
For renaming files, you could simply use the rename utility.
rename 's/_EXP_.*?(?=.[^.]*$)//' *.*
Try the above command on the directory where the files you want to rename are located.
Related
Is it possible to copy only a group of files without erasing some files in destination folder.
I have a folder « One » with contain :
file-b.php
file-d.php
In folder « two », I have
file-a.php
file-b.php
file-c.php
file-d.php
I want to copy files from folder « One » to folder « two » I just want to replace file-b.php end file-d.php without erasing file-a.php and file-d.php
A the end, folder « two », should be like this :
file-a.php
file-b.php (modified)
file-c.php
file-d.php (modified)
I've tried various things with mv and cp without success.
I thought I should delete my question since I found a solution. In case it could help, here is my solution :
cp -Rf /path/to/folder-1/* /path/to/folder-2
-R instructs cp to copy files recursively (for example, a whole directory). To overwrite already existing files you should use the -f argument:
I want to convert all .pdf files in a folder into .txt files with make without using loops and with the help of pdftotext. The new .txt files shall keep the original file name. Additionally, the new file gets a new file extension.
Example:
test1.pdf --> test2.newextension
Everything's written within a Makefile file. I start the conversion by typing in "make converted" in my console.
My first (miserable) attempt was:
converted:
#ls *.pdf | -n1 pdftotext
However, there are 3 things still missing with it:
It doesn't repeat the process
The new file extension isn't being added to the newly created files.
Is the original name being kept or being given to the pdftotext function?
I used to program with the bash and Makefile is completely new to me. I'd be thankful for answers!
You can refer to this simple example:
SOURCES ?= $(wildcard *.pdf)
%.txt: %.pdf
pdftotext $< $#
all: $(SOURCES:%.pdf=%.txt)
clean:
rm -f *.txt
If no SOURCE was defined, it'll just try to get all *.pdf files from the local directory.
Then we define a pattern rule teaching make how to make *.txt out of *.pdf.
We also define target all that tried to make a txt file for each .pdf file in SOURCES variable.
And also a clean rule deleting quietly all .txt files in current dir (hence be careful, potentially dangerous).
I am trying to add .pdf to the filename of files without extension in a folder.
It is possible to rename for example txt files to pdf using the following command:
FileMove, %SourceFolder%\*.txt, %SourceFolder%\*.pdf
Also, I can add .pdf to all files by:
FileMove, %SourceFolder%\*, %SourceFolder%\*.pdf
But I only want to target only the files without extension. How to do this?
Example
As suggested by kasper and MCL
SetWorkingDir %A_ScriptDir%
Loop, files\*
{
if !StrLen(A_LoopFileExt) ; if no file extension
{
FileMove,%A_LoopFileFullPath%,%A_LoopFileFullPath%.pdf ;rename file
}
}
see [Loop, FilePattern]
see [FileMove]
#kasper, You can use windows command prompt to rename the file as well as change the extension.
Just navigate to the file directory and use command
ren abc.txt abc.pdf
Here abc.txt is old file and abc.pdf is pdf of abc.txt.
My situation is I only have execute permission from some folder:
Lets say, I would like to backup entire folder and exclude some folder and files with exclude.txt
Here is path I would like to backup:
/pdf/data/pdfnew/2014
And I only have permission to execute from this folder (main):
/pdf/data/pdfnew/2014/public/main
I put exclude.txt in same folder which I can execute the command (main)
I execute this command in (main folder):
tar -cjvf -X exclude.txt 2014.tar.bz2 /pdf/data/pdfnew/2014
The result is it still included folder that I dont want to backup.
Is there a correct way doing this?
Do you have a user/home directory on that server? You should, so you should just place exclude.txt in your user/homedirectory on that server & run it like this from that directory:
tar -cjvf -X ~/exclude.txt ~/2014.tar.bz2 /pdf/data/pdfnew/2014
The ~/ is a shorthand for your user/home directory so in this case it is explicitly stating, “Read exclude.txt from the user/home directory & write ~/2014.tar.bz2 to the user/home directory.
But you also ask this:
Is there a correct way doing this?
There is never one canonical best way of doing something like this. It is all based on your final/end goal. Nothing more. Nothing less. That said, if I were you I would do it like this instead using the -C option:
tar -cjvf -X ~/exclude.txt ~/2014.tar.bz2 -C /pdf/data/pdfnew/ 2014
The uppercase -C option allows tar to internally change the working directory to /pdf/data/pdfnew/ so you can then create an archive of 2014 without having to have the whole directory tree retained in the backup. I find this is easier to work with because many times I want to backup the contents of a directory but have no use to retain the parent structure. That way the archive is more like a traditional ZIP archive which I find is easer to understand & work with.
I am using move command mv -f $file1 $file2 to move a file from source directory to a destination directory. I am getting a failure message as:
mv: cannot create regular file $file2:File exists
Could you let me know on the reason for such failures from move command?
Are there any ways to solve this error?
This is caused by race condition. Your were running multiple mv in your scripts.
Does that file really exist? If it exists, and you are SURE that you want to overwrite it, add the -f flag, which will force the command to continue;
mv -f file1 file2
This error can be caused by a privileges conflict and occasionally by using illegal characters in the file name. Make sure there are no unusual special characters in the file's name and verify that there is not already a file with the same name in the directory that the file is being moved to. You might need to use ls -l from above target directory to see if the privileges settings will allow you to read/write to the directory.