Detailed explanation of Linux one-line command to process batch files

Detailed explanation of Linux one-line command to process batch files

Preface

The best method may not be the one you can think of the fastest. Scripts for temporary use at work do not need to be robust, and the faster they are written, the better. Here is a technique for using the sed command to construct commands to process batch files for reference.

Demand Case 1

Copy all 0_80_91.txt, 0_80_92.txt, 0_80_93.txt, etc. in the current directory. . . The file names of dozens of files were changed to 0_81_91.txt, 0_81_92.txt, 0_81_93.txt, etc. That is, change 80 in the file name to 81.

The implementation command is: ls *.txt |sed -nr 's/(0_)(80)(.*)/mv \1\2\3 \181\3/gp' | sh

#ls *.txt 
0_80_91.txt 0_80_92.txt 0_80_93.txt
#ls *.txt |sed -nr 's/(0_)(80)(.*)/mv \1\2\3 \181\3/gp'
mv 0_80_91.txt 0_81_91.txt
mv 0_80_92.txt 0_81_92.txt
mv 0_80_93.txt 0_81_93.txt
#ls *.txt |sed -nr 's/(0_)(80)(.*)/mv \1\2\3 \181\3/gp' | sh
#ls *.txt
0_81_91.txt 0_81_92.txt 0_81_93.txt

Demand Case 2

Decompress all 0_80_91.Z, 0_80_92.Z, and 0_80_93.Z files in the current directory using the cc_uncompress command and output them to the specified file. The calling format is cc_uncompress -s 0_80_91.txt -d 1.txt. 1.txt can be any file name.

The implementation command 1 is: ls *.Z | sed -nr 's/(.*)/cc_uncompress -s \1 -d \1.txt/gp'

#ls *.Z | sed -nr 's/(.*)/cc_uncompress -s \1 -d \1.txt/gp'
cc_uncompress -s 0_80_91.Z -d 0_80_91.Z.txt
cc_uncompress -s 0_80_92.Z -d 0_80_92.Z.txt
cc_uncompress -s 0_80_93.Z -d 0_80_93.Z.txt
#ls *.Z | sed -nr 's/(.*)/cc_uncompress -s \1 -d \1.txt/gp' | sh

The implementation of command 2 is: find . -name "*.Z" -exec cc_uncompress -s {} -d {}.bak \;

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to deal with the prompt "Operation not permitted" when deleting files in Linux
  • Linux finds and processes files with spaces after the file name (two methods)
  • Linux file processing common command operation skills
  • Methods for processing various compressed files under Linux
  • Using winscp and batch processing under Windwos to upload files to Linux server through SSH port
  • How to enter directory/folder in Linux without using CD command
  • How to decompress multiple files using the unzip command in Linux

<<:  Ubuntu16.04 installation mysql5.7.22 graphic tutorial

>>:  MySQL 5.6.23 Installation and Configuration Environment Variables Tutorial

Recommend

MySQL deduplication methods

MySQL deduplication methods 【Beginner】There are v...

CentOS7 upgrade kernel kernel5.0 version

Upgrade process: Original system: CentOS7.3 [root...

CSS3 to achieve timeline effects

Recently, when I turned on my computer, I saw tha...

Analysis of the principles of Mysql dirty page flush and shrinking table space

mysql dirty pages Due to the WAL mechanism, when ...

Detailed steps for debugging VUE projects in IDEA

To debug js code, you need to write debugger in t...

How to quickly build your own server detailed tutorial (Java environment)

1. Purchase of Server 1. I chose Alibaba Cloud...

Should I abandon JQuery?

Table of contents Preface What to use if not jQue...

How to use JS to check if an element is within the viewport

Preface Share two methods to monitor whether an e...

Implementation of navigation bar and drop-down menu in CSS

1. CSS Navigation Bar (1) Function of the navigat...

Explanation on whether to choose paging or loading in interactive design

The author of this article @子木yoyo posted it on hi...

Example code for converting html table data to Json format

The javascript function for converting <table&g...

MySQL 8.0.12 installation steps and basic usage tutorial under Windows

This article shares the installation steps and us...

Implementation code for using mongodb database in Docker

Get the mongo image sudo docker pull mongo Run th...

Native JS realizes uniform motion of various sports

This article shares with you a uniform motion imp...