unix command to change file name [duplicate] - shell

This question already has answers here:
How to do a mass rename?
(11 answers)
Closed 9 years ago.
I have to change
<<STORE>>SA_MASTER_YYYMMDDHHMMSS.dat file name to
SA_MASTERYYYMMDDHHMMSS.<<STORE>>. Please tell me the command in unix to achieve this
for example
0001.SAMASTER_YYYYMMDDHHMMSS.DAT should be changed to SAMASTER_YYYYMMDDHHMMSS.1 ie if the store has leading zero(0001) i have to eliminate the zeros(1)

use mv.
e.G. mv 0001.SAMASTER_YYYYMMDDHHMMSS.DAT SAMASTER_YYYYMMDDHHMMSS.1
For the interpretation you will need to write some script.
See How to do a mass rename? for further answers.

Of course, the direct method is using mv. However, if you want to rename a lot of files' names, you need write a program, you need sed,cut and so on

Related

Create Batch Script to Scan Multiple Files [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I'm looking to make a batch script. What I have is a ton of different logs in a ton of different places, all with a bit of important info and a lot of useless info.
Some of these logs are directly named, and some are named by date and time.
I'm trying to make a script that can basically scan them for me so I don't have to go through each folder and log and scan manually.
Some examples:
OmegaManager\logs\omega.log - scan for "State:" and "has been updated"
OmegaManager\logs\instance-0.log - scan for "shutdown"
KRBanking\PlayerDatabase*logs are numbers* - copy all information or scan for changes since last time?
KRBanking\ServerLogs*logs are dates and times* - scan for "Deposited" and "Withdrawed"
And then output the whole line.
Is this even moderately possible? Thanks in advance.
Yes, this is possible. Batch files support loops, conditions, and filtering/searching.
A FOR loop allows you to iterate through files or directories, you'll find more information in this SO post.
To find strings in a file, you have several options, i.e. find and findstr, see riptutorial.com:
FIND can scan large files line-by-line to find a certain string with no wildcard support.
FINDSTR has more features and supports regular expressions with wildcards in the search string.
Super simple example for one of your use cases
The batch script must be placed where your files are. Otherwise, you need to add a full path instead of just "omega.log".
FINDSTR /L /C:"State:" /C:"has been updated" omega.log
To start with batch programming, you can read the findstr documentation and some tutorials.

Search / replace in bash script with dynamic part [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I'm writing a bash script and I want to edit a PHP config file, find a string and replace by another.
The hard part is that I want this search/replace to be dynamic.
Here is an example:
define('APP_VERSION', '1.0.31');
The goal is to replace 1.0.31 by another version number.
How could I achieve that? I've tried with sed, but can't isolate the version number part (because it's not always the same, so I can't directly search for 1.0.31)
Thanks
The point of regexes is to match non-static text. To replace any version number with 123 use
sed "s/define('APP_VERSION', *'[^']*')/define('APP_VERSION', '123')/"

Bash - How to share constants between scripts? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to make it so that there isn't a list of constants at the top of every bash script i have? I have a lot of readonly constants for formatting and such but having them at the top of every single one of my scripts takes up space. Is there a way to make a separate script containing all of them and access it or something? or some way to clean it up?
Use a common script that you source in your other scripts.
E.g. source common.sh will execute that file and you may export variables there.
This is also how files like .bashrc and .bash_profile work, it is sourced when you execute bash (the latter when it is a login shell). When you change .bashrc, you can source it again in the running shell for the changes to take effect.

How to read a specific line data [duplicate]

This question already has answers here:
VBScript to read specific line and extract characters and store it as a variable
(2 answers)
How to delete the first row in the .csv file
(2 answers)
Closed 5 years ago.
I want to read a specific line from the text file using VBScript.
I have explored Read and ReadLine methods but I can't able to read only specific line from text file. (I have 1000 of line but I want to read only 99 or 200 or 500 line only)
The question may be similar to the questions those duplicate hunters pointed to, but the answers are - for different reasons - of no use. A good answer could be build from one answer to the completely different question here.
Now to the answer:
Use a .SkipLine loop to read to the line before you are interested in and get it using .ReadLine.

Get back the output of os.execute in Lua [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Get back the output of os.execute in Lua
I want to assign the result of a shell command to a lua variable.
Any better way in lua 5.1 than what is answered here?
Get back the output of os.execute in Lua
You can use io.popen for this (included in Lua 5.1). That gives you a file handle which you can use to either write or read from (to) the program. More info in the Lua Manual.

Resources