Showing posts with label Multiple. Show all posts
Showing posts with label Multiple. Show all posts

04 February 2023

How to rename multiple file names all at once?

https://ostechnix.com/how-to-rename-multiple-files-at-once-in-linux/


Method 4 - Rename multiple files at once using vimv

As the name says, Vimv is a command line utility to bulk rename files using Vim editor. You can, of course, change the editor by changing the value of $EDITOR environment variable.

To install Vimv, git clone the repository:

$ git clone https://github.com/thameera/vimv.git

Copy the vimv binary to your $PATH, for example /usr/local/bin/.

$ sudo cp vimv/vimv /usr/local/bin/

Finally, make it executable:

$ sudo chmod +x /usr/local/bin/vimv

Now go to the directory and run the following command to edit the filenames.

$ vimv

You will see the filenames in Vi editor. Press i to switch to interactive mode and edit the filenames as the way you edit text in Vi editor. Once done, press ESC key and type :wq to save and exit.

The files inside the directory should be renamed now.

 

Method 3 - Rename files using renameutils

The renameutils is a set of programs that is designed to batch renaming files and directories faster and easier.

Renameutils consists of the following five programs:

  1. qmv (quick move),
  2. qcp (quick copy),
  3. imv (interactive move),
  4. icp (interactive copy),
  5. deurlname (delete URL).

Install renameutils in Linux

Renameutils is available in the default repositories of most Linux distributions. To install it on Arch-based systems, enable the community repository and run:

$ sudo pacman -Syu renameutils

On Debian-based systems:

$ sudo apt install renameutils

Now, let us see some examples.

1. qmv

The qmv program will open the filenames in a directory in your default text editor and allows you to edit them.

I have the following three files in a directory named 'ostechnix'.

$ ls ostechnix/
abcd1.txt abcd2.txt abcd3.txt

To rename the filenames in the 'ostechnix' directory, simply do:

$ qmv ostechnix/

Now, change the filenames as you wish. You will see the live preview as you edit the filenames.

Alternatively, you can cd into the directory and simply run 'qmv'.

Once you opened the files, you will see the two columns as shown in the following screenshot.

Bulk rename files using qmv
Bulk rename files using qmv

The left column side displays the source filenames and the right column displays the destination names (the output filenames that you will get after editing).

Now, rename all the output names on the right side as you wish.

Bulk rename files using qmv
Bulk rename files using qmv

After renaming filenames, save and quit the file.

Finally, you will see the following output:

Plan is valid.

abcd1.txt -> xyzd1.txt
abcd2.txt -> xyzd2.txt
abcd3.txt -> xyzd3.txt
   Regular rename

abcd1.txt -> xyzd1.txt
abcd2.txt -> xyzd2.txt
abcd3.txt -> xyzd3.txt

Now, check if the changes have actually been made using 'ls' command:

$ ls ostechnix/
xyzd1.txt xyzd2.txt xyzd3.txt

See? All files are renamed. Not just files, the renameutils will also rename the directory names as well.

Here is a quick video demo of qmv program:

Bulk rename files using qmv
Bulk rename files using qmv

If you don't want to edit the filenames in dual-column format, use the following command to display the destination file column only.

$ qmv -f do ostechnix/

Where, '-f' refers the format and 'do' refers destination-only.

Now, you will see only the destination column. That's the column we make the changes.

Display the destination file column only in qmv
Display the destination file column only in qmv

Once done, save and close the file.

For more details, refer man pages.

$ man qmv

 

01 January 2022

How to amend older commit messages in git?

How to amend older commit messages in git?


https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History


Changing Multiple Commit Messages

To modify a commit that is farther back in your history, you must move to more complex tools. Git doesn’t have a modify-history tool, but you can use the rebase tool to rebase a series of commits onto the HEAD that they were originally based on instead of moving them to another one. With the interactive rebase tool, you can then stop after each commit you want to modify and change the message, add files, or do whatever you wish. You can run rebase interactively by adding the -i option to git rebase. You must indicate how far back you want to rewrite commits by telling the command which commit to rebase onto.

For example, if you want to change the last three commit messages, or any of the commit messages in that group, you supply as an argument to git rebase -i the parent of the last commit you want to edit, which is HEAD~2^ or HEAD~3. It may be easier to remember the ~3 because you’re trying to edit the last three commits, but keep in mind that you’re actually designating four commits ago, the parent of the last commit you want to edit:

$ git rebase -i HEAD~3

Remember again that this is a rebasing command — every commit in the range HEAD~3..HEAD with a changed message and all of its descendants will be rewritten. Don’t include any commit you’ve already pushed to a central server — doing so will confuse other developers by providing an alternate version of the same change.

Running this command gives you a list of commits in your text editor that looks something like this:

pick f7f3f6d Change my name a bit
pick 310154e Update README formatting and add blame
pick a5f4a0d Add cat-file

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out


It’s important to note that these commits are listed in the opposite order than you normally see them using the log command. If you run a log, you see something like this:

$ git log --pretty=format:"%h %s" HEAD~3..HEAD
a5f4a0d Add cat-file
310154e Update README formatting and add blame
f7f3f6d Change my name a bit

Notice the reverse order. The interactive rebase gives you a script that it’s going to run. It will start at the commit you specify on the command line (HEAD~3) and replay the changes introduced in each of these commits from top to bottom. It lists the oldest at the top, rather than the newest, because that’s the first one it will replay.

You need to edit the script so that it stops at the commit you want to edit. To do so, change the word “pick” to the word “edit” for each of the commits you want the script to stop after. For example, to modify only the third commit message, you change the file to look like this:

edit f7f3f6d Change my name a bit
pick 310154e Update README formatting and add blame
pick a5f4a0d Add cat-file


When you save and exit the editor, Git rewinds you back to the last commit in that list and drops you on the command line with the following message:

$ git rebase -i HEAD~3
Stopped at f7f3f6d... Change my name a bit
You can amend the commit now, with

       git commit --amend

Once you're satisfied with your changes, run

       git rebase --continue


These instructions tell you exactly what to do. Type:

$ git commit --amend

Change the commit message, and exit the editor. Then, run:

$ git rebase --continue

This command will apply the other two commits automatically, and then you’re done. If you change pick to edit on more lines, you can repeat these steps for each commit you change to edit. Each time, Git will stop, let you amend the commit, and continue when you’re finished.


21 December 2021

How to change multiple rows into one row in vim?

How to change multiple rows into one row in vim?

Check how many rows are there totally (e.g. 50)

50J

How to change a one-row text into multiple rows in vim?

How to change a one-row text into multiple rows in vim?

:%s/; /\r/g

The above command replaces '; ' with \r (carriage return)

17 December 2014

How to sum data from different Excel sheets?

It is referred to as to consolidate data from multiple sheets into a master sheet.

1. Drag your mouse to select the cells corresponding to those in multiple sheets. Note: It would not work if you click the top-left corner box.
2. Date | Consolidate.
3. Click the icon under 'Reference'.
4. Go to the first data sheet, and drag-select all the cells. Click the icon again. Click 'Add'.
5. Go to the second data sheet, and repeat Step 4. Repeat until all the data sheets are done.
6. Click OK.

Done.

In addition to 'Addition', you can also do average, counting, max, min, product, etc.