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
- 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
- How to Use Shell Script Sleep Command
- Bash: How to Check if the File Does Not Exist
- How to use bash get script directory in Linux
- 20 Examples of Bash Find Command
- Bash: How to Check if String Not Empty in Linux
- Linux: Sudo in Bash Scripts
- Linux: Bash Printf Examples
- Linux: Bash First Line
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- A Bash Nested Loop
- Use a Shell Script to Send an Email
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- Learn about useful bash scripts
- About chaining bash commands
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- Learn about C shell script
- Learn about Korn shell scripting
- 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
- Copy command in shell scripts
- Install Oracle Database
- About a bash date command
- Guide in Pictures
- 5 Basic Shell Script Examples for Your First Script
- Bash Time Command on Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 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 split strings in Linux
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: $0 in a Shell Script
- A crontab service shell script
- A Bash Multiline Command
- Linux: A Bash Linter
- A Bash Test Command
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- AWK in a Bash Script
- Learn about systemd startup script
- Learn about a bash error code
- Using a bash tee command
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Learn to run Perl script in Linux
- Examples of using the Expect
- Shell script usage
- Here is everything you need to know about Bash for Windows
