Cut in Shell Script Examples
Here you will find out:
- about Shell script cut
- examples of script cut
- when DiskInternals can help you
Are you ready? Let's read!
About Shell Script Cut
The Command is cut in shell script used to split text and select the necessary parts, followed by writing to standard output. This utility is part of GNU Coreutils, so it is by default available on all Linux distributions.
The basic syntax is as follows:
If necessary, you can specify not one file, but several. For more details, enter the command 'cut --help' and you will learn much more.
-d option - delimiter
-d (--delimiter = DELIM) - this function allows you to set your own separator instead of the standard TAB. This option is not found alone, it is recommended to use it with -f (--fields = LIST) - fields for cutting.
Example: there is a CSV file called people.csv.
You need to cut the first field:
If you need to cut several fields, you just need a comma:
Nothing complicated, just utmost care is needed.
-c option - cut by character
-c (--characters = LIST) - an option that allows you to cut a specific character or several of them. This function is superior to working with bytes, as it is easier to use and does not depend on the number of bytes.
An example would be with the symbol ♣
You can specify a specific range of characters, separated by dashes, or only selected characters, separated by commas. As you can see, with a single command, you can perform many actions.
-b option - cut by byte position
-b (--bytes = LIST) - a function that allows cutting by byte number, set, or range of bytes.
There can be a huge number of examples; here are the most common cases of using this function.
The same command with ranges
A command for cutting by bytes:
- From 1 byte to the end:
- From 1 byte to 3 bytes:
By analogy, you can apply your values.
- complement - cut by complement
This function is slightly different from the others in its meaning.
--complement - specifies the characters, bytes, or fields that will remain in the file, and everything else will be cut.
This option can be used in conjunction with the -f or -c options.
For example:
Another example:
These functions are very useful when working with large text documents. Saving time also plays an important role.
Want to use Linux files on Windows?
DiskInternals Linux Reader is a unique, unparalleled application that allows you to get files from Linux to Windows. This is especially useful when you are using a virtual machine or dual boot. The application is available in a trial version at no cost with the ability to view files. DiskInternals Linux Reader gives you Windows access to various Linux file systems, such as HFS, Ext2/Ext3/Ext4, ReiserFS, and others. The program professionally moves files without unnecessary options, without advertising and other things.
If you want more features, then there is no need to look for something else - you can simply update the program to a more advanced version and use the already large arsenal of options. If you are quite comfortable with the standard set of actions in the DiskInternals Linux Reader, this is great; use it and be satisfied.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command
