{"id":128415,"date":"2025-05-19T07:09:18","date_gmt":"2025-05-19T07:09:18","guid":{"rendered":"\/tutorials\/?p=128415"},"modified":"2026-03-09T19:16:34","modified_gmt":"2026-03-09T19:16:34","slug":"linux-cut-command","status":"publish","type":"post","link":"\/ng\/tutorials\/linux-cut-command\/","title":{"rendered":"Linux cut command: Syntax, options, and practical examples"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>When working with Linux, you&rsquo;ll often deal with structured text data in a file, output from a command, or characters generated by a script. Most of the time, you don&rsquo;t need all of it. You might just want a specific column, a few characters, or one particular part of each line. That&rsquo;s where the <strong>cut <\/strong>command comes in.<\/p><p><strong>cut <\/strong>is a simple, built-in Linux command that extracts parts of text from each input line. It can work based on character positions, byte offsets, or fields separated by a delimiter character. It&rsquo;s fast, script-friendly, and great for trimming output to just the pieces you care about.<\/p><p>This guide will explain how <strong>cut <\/strong>works, how to use its main options, and where it fits in both everyday use and real-world scripts. If you&rsquo;re getting more comfortable with the Linux command line utility, this is a tool you&rsquo;ll use more often than you might expect.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/div><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-linux-cut-command-syntax-overview\"><strong>Linux cut command Syntax overview<\/strong><\/h2><p>The basic syntax of the <strong>cut <\/strong>command in Linux depends on where the input data comes from. You can use <strong>cut <\/strong>in two main ways:<\/p><ul class=\"wp-block-list\">\n<li><strong>With an input file &ndash;<\/strong> Pass the text file&rsquo;s name as an argument, then cut reads and processes each line.<\/li>\n\n\n\n<li><strong>With standard input (stdin) &ndash;<\/strong> Pipe the output of another command directly into cut using<strong> |<\/strong>.<\/li>\n<\/ul><p>This flexibility means the <strong>cut <\/strong>command works with almost anything that produces line-based output &ndash; files, command results like <strong>ls<\/strong>, <strong>ps<\/strong>, or <strong>cat<\/strong>, and even simple <strong>echo <\/strong>statements in scripts.<\/p><p>Here&rsquo;s what the general syntax looks like:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut [OPTION] [VALUE] [FILE]\n[DATA] | cut [OPTION] [VALUE]<\/pre><p>The <strong>cut <\/strong>command returns data in <strong>standard output (stdout)<\/strong>.<\/p><p><strong>Key options for the cut command<\/strong><\/p><p>The cut command has three main options:<\/p><ul class=\"wp-block-list\">\n<li><strong>-c (character)<\/strong> &ndash; selects a single character or multiple characters defined from each line based on their specified position.<\/li>\n\n\n\n<li><strong>-b (byte)<\/strong> &ndash; selects a single byte or multiple bytes from each line.&nbsp;<\/li>\n\n\n\n<li><strong>-f (field)<\/strong> &ndash; extracts fields split by a delimiter. This is the most commonly used option in practice.<\/li>\n<\/ul><p>The three primary options require a numerical value, which can indicate:<\/p><ul class=\"wp-block-list\">\n<li><strong>Exact position &ndash;<\/strong> a single value. Using <strong>-f 2<\/strong> will return the second field in a line. Fields can <strong>only <\/strong>use exact positions.<\/li>\n\n\n\n<li><strong>Range &ndash; <\/strong>A list of numbers separated by a<strong> <\/strong>hyphen. Using <strong>-b <\/strong>2-5 will return the specific bytes between <strong>2 <\/strong>and <strong>5<\/strong>.<\/li>\n\n\n\n<li><strong>LIST argument &ndash; <\/strong>A combination of the above, separated by commas. Using <strong>-c 1,5-7 <\/strong>will return the first character and characters 5, 6, and 7.<\/li>\n<\/ul><p>You can also pass additional options to the <strong>cut <\/strong>command:<\/p><ul class=\"wp-block-list\">\n<li><strong>-d &ndash; <\/strong>sets the input delimiter when working with fields. This acts as a field separator between multiple fields. The default delimiter is the <strong>Tab <\/strong>character.<\/li>\n\n\n\n<li><strong>&ndash;output-delimiter &ndash;<\/strong> sets a different output delimiter when selecting multiple fields. It matches the <strong>-d <\/strong>option if not specified.<\/li>\n\n\n\n<li><strong>&ndash;complement &ndash;<\/strong> inverts the selection. Instead of including the specified bytes, characters, or fields, it excludes them and returns everything else.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-linux-cut-command-examples\"><strong>Linux cut command examples<\/strong><\/h2><p>Now that we&rsquo;ve covered the fundamentals, let&rsquo;s see how each cut option works in practice.<\/p><h3 class=\"wp-block-heading\" id=\"h-using-cut-by-characters-and-bytes\"><strong>Using cut by characters and bytes<\/strong><\/h3><p>The <strong>cut <\/strong>command lets you extract specific parts of each line using either <strong>characters (-c)<\/strong> or <strong>bytes (-b<\/strong>). Theoretically, these options serve different purposes &ndash; &ndash;<strong>c<\/strong> for selecting specific characters, and<strong> -b<\/strong> for exact byte positions.<\/p><p>This made sense when Linux primarily used <strong>ASCII<\/strong>, where each character was exactly one byte, and it was standard for a specific byte to indicate a particular value, such as the first byte indicating the log level in a historical logging solution.<\/p><p>Modern systems use <strong>UTF-8<\/strong>, which supports multibyte characters like <strong>&egrave; <\/strong>or <strong>&ntilde;<\/strong>. However, the <strong>cut <\/strong>command isn&rsquo;t multibyte-aware, so when using <strong>-c<\/strong>, it still assumes single-byte characters. In practice, this means <strong>-b<\/strong> and <strong>-c<\/strong> behave the same in most modern use cases.<\/p><p>Here&rsquo;s a quick example to demonstrate:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"cr&egrave;me\" &gt; sample.txt\ncut -c 2-4 sample.txt\ncut -b 2-4 sample.txt<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a800e1d\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a800e1d\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"318\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_char_and_byte_example.png\/w=1024,h=1024,fit=scale-down\" alt=\"Display of the cut command when using both the character and byte options, and how the outputs match in a modern Linux distribution.\" class=\"wp-image-128420\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_char_and_byte_example.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_char_and_byte_example.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_char_and_byte_example.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_char_and_byte_example.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_char_and_byte_example.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Let&rsquo;s break down the word <strong>cr&egrave;me<\/strong>:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong>Letter<\/strong><\/td><td>c<\/td><td>r<\/td><td>&egrave;<\/td><td>m<\/td><td>e<\/td><\/tr><tr><td><strong>Byte<\/strong><\/td><td>1<\/td><td>2<\/td><td>3-4<\/td><td>5<\/td><td>6<\/td><\/tr><\/tbody><\/table><\/figure><p>The key detail is that the special character <strong>&egrave; <\/strong>occupies <strong>2 <\/strong>bytes of storage. Hence, even though you defined the starting position as <strong>2 <\/strong>and the ending position as <strong>4<\/strong>, which should result in three<strong> <\/strong>characters, you only get two.<\/p><p>If you try to extract just the third character, here&rsquo;s what happens:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut -c 3 sample.txt\ncut -b 3 sample.txt<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a801dde\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a801dde\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"272\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cutting_multibyte_example.png\/w=1024,h=1024,fit=scale-down\" alt=\"Display of what occurs when you use the cut command with characters and bytes on a character which requires multiple bytes to store.\" class=\"wp-image-128421\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cutting_multibyte_example.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cutting_multibyte_example.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cutting_multibyte_example.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cutting_multibyte_example.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cutting_multibyte_example.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Since the 3rd byte&rsquo;s position is half of the <strong>&egrave; <\/strong>character, the cut command prints an unintelligible symbol.<\/p><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Pro tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> We recommend using the <a href=\"\/ng\/tutorials\/awk-command\/\">awk command<\/a> if you expect to use multibyte characters. In this example, <strong>awk '{print substr($0, 3, 1)}' sample.txt<\/strong> would return the special character correctly, since it can understand <strong>UTF-8<\/strong> encoding.<\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-using-cut-by-fields\"><strong>Using cut by fields<\/strong><\/h3><p>The <strong>-f<\/strong> option is used to extract specific fields from each input line. It can be used with a delimiter that separates these fields, like a comma or space character, or it can use the default tab delimiter.<\/p><p>Here&rsquo;s an example that simulates a basic user status table:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">printf \"nametstatustrolenalicetactivetadminnbobtinactivetguestn\" &gt; users.txt<\/pre><p>This command creates a file called <strong>users.txt<\/strong> with tab-separated values. Each line contains three fields: the user&rsquo;s name, status, and role.<\/p><p>To extract just the usernames, you can use:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut -f 1 users.txt<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a802d9f\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a802d9f\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"228\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_default_example.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of the cut command being used with the field option without any extra parameters on a sample, tab-separated file.\" class=\"wp-image-128424\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_default_example.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_default_example.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_default_example.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_default_example.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_default_example.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>You can also ask for multiple fields. To get the username and role, you can run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut -f 1,3 users.txt<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a803d11\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a803d11\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"286\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_multiple.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of the cut command with the field option where multiple fields are specified as the output.\" class=\"wp-image-128425\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_multiple.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_multiple.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_multiple.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_multiple.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_field_multiple.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-using-a-custom-delimiter\"><strong>Using a custom delimiter<\/strong><\/h3><p>Most of the data you&rsquo;ll encounter isn&rsquo;t <strong>tab<\/strong>-separated. You&rsquo;ll often work with files or command output where commas, colons, or other symbols separate fields, and the default tab delimiter won&rsquo;t work. To make the <strong>cut <\/strong>command work in these cases, you can define a specific character as the delimiter with the <strong>-d<\/strong> option.<\/p><p>Let&rsquo;s have a look at an environment file you could find in an application that&rsquo;s hosted on a Linux server:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a8049fd\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a8049fd\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"447\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/env-file-example.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of a basic environment file that stores values for a MySQL database connection.\" class=\"wp-image-128426\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/env-file-example.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/env-file-example.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/env-file-example.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/env-file-example.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/env-file-example.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To get all of the values from this file, you can use:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut -f 2 -d = mysql.env<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a805622\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a805622\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"314\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_mysql_env.png\/w=1024,h=1024,fit=scale-down\" alt=\"Usage of the cut command with the field option, with the custom delimiter being set.\" class=\"wp-image-128427\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_mysql_env.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_mysql_env.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_mysql_env.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_mysql_env.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_mysql_env.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>In this command, you define the field delimiter as <strong>=<\/strong>, which means anything before or after that symbol on each line is to be counted as a field. Then, you use cut to extract the field that you want.<\/p><h3 class=\"wp-block-heading\" id=\"h-excluding-non-delimited-lines\"><strong>Excluding non-delimited lines<\/strong><\/h3><p>By default, the cut command processes every line, even if a line doesn&rsquo;t contain the delimiter you&rsquo;ve specified. This can return unexpected results.<\/p><p>Let&rsquo;s assume the <strong>mysql.env<\/strong> file has a comment in it:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a806329\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a806329\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"437\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment.png\/w=1024,h=1024,fit=scale-down\" alt=\"Sample environment file for MySQL database connection details, including a top-line comment.\" class=\"wp-image-128428\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If you run the same cut command as before, you now get:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a807309\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a807309\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"364\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_comment.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of the cut command's behaviour when using a delimiter on a file where lines may not contain it.\" class=\"wp-image-128429\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_comment.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_comment.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_comment.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_comment.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_comment.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Since the delimiter is absent in the line, it returns the entire row.<\/p><p>To exclude lines like these, the <strong>cut <\/strong>command also has an <strong>-s <\/strong>option. It excludes any lines from the output that do not contain the delimiter, so that only the values you care about are returned. Let&rsquo;s run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut -f 2 -d = -s mysql.env<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a8081e2\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a8081e2\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"297\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_s_option.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of the -s option with the cut command, where the extra comment line is now dropped due to the delimiter not being present in it.\" class=\"wp-image-128430\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_s_option.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_s_option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_s_option.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_s_option.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_delimiter_with_s_option.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Now, it excludes any line where the specified delimiter is not present. Since our comment does not have the <strong>= <\/strong>symbol, it gets dropped.<\/p><h3 class=\"wp-block-heading\" id=\"h-using-cut-with-pipes\"><strong>Using cut with pipes<\/strong><\/h3><p>One of the most practical ways to use the cut command in Linux is as part of a pipeline. Instead of reading from a file, you can feed it the output of another command using the pipe operator (|).<\/p><p>Here&rsquo;s a basic example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"name=admin\" | cut -d '=' -f 2<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a808fbb\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a808fbb\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"131\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_pipe.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of the cut command being used on the standard output of a separate command by using the pipe operator.\" class=\"wp-image-128432\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_pipe.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_pipe.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_pipe.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_pipe.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/cut_by_pipe.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>This works the same way as reading from a text file, but processes the standard output of the piped data instead.<\/p><p>Using <strong>cut <\/strong>in pipes is especially helpful in scripts or one-liners when you need to process text quickly without creating intermediate files.<\/p><h2 class=\"wp-block-heading\" id=\"h-real-life-use-cases-for-the-cut-command\"><strong>Real-life use cases for the cut command<\/strong><\/h2><p>Now that you know how the <strong>cut <\/strong>command works, let&rsquo;s see how to use it effectively in some real scenarios.<\/p><h3 class=\"wp-block-heading\" id=\"h-cutting-specific-fields-from-a-csv-file\"><strong>Cutting specific fields from a CSV file<\/strong><\/h3><p>Comma-separated value (CSV) files are a common way to store and share structured data &ndash; user lists, exports from web apps, billing reports, or logs. But most of the time, you don&rsquo;t need the whole file &ndash; you just need one or two specific columns. That&rsquo;s where the <strong>cut <\/strong>comes in.<\/p><p>In this example, you are managing a web app and must email all active users. You export your user list, and it gives you a <strong>users.csv<\/strong> file like this:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a809d03\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a809d03\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"375\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/users_csv_example.png\/w=1024,h=1024,fit=scale-down\" alt=\"Sample users.csv file containing dummy user details on a web application.\" class=\"wp-image-128433\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/users_csv_example.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/users_csv_example.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/users_csv_example.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/users_csv_example.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/users_csv_example.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>To get a list of just the active email addresses, you can combine <strong>grep <\/strong>and <strong>cut<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">grep ',active$' users.csv | cut -d ',' -f 3 &gt;&gt; active.txt<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a80a9b3\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a80a9b3\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"174\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/parsing_csv_with_cut.png\/w=1024,h=1024,fit=scale-down\" alt=\"Example of the cut command being used in tandem with the grep command to produce an email list of active users.\" class=\"wp-image-128435\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/parsing_csv_with_cut.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/parsing_csv_with_cut.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/parsing_csv_with_cut.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/parsing_csv_with_cut.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/parsing_csv_with_cut.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>This will store all the emails of all active users into an <strong>active.txt <\/strong>file, which you can then use as a mailing list.<\/p><p>This is where the <strong>cut<\/strong> command shines: the CSV file is already structured, and you only need one specific column. It&rsquo;s fast, reliable, and easy to chain with other commands like <strong><a href=\"\/ng\/tutorials\/grep-command-in-linux\/\">grep<\/a> <\/strong>when working directly in the terminal.<\/p><h3 class=\"wp-block-heading\" id=\"h-loading-database-credentials-from-an-env-file\"><strong>Loading database credentials from an .env file<\/strong><\/h3><p>Connecting to a MySQL database from the terminal is quite tedious. To make this easier, many developers use<strong> .env<\/strong> files to store database credentials and write simple scripts to automate the connection.<\/p><p>Let&rsquo;s take another look at our <strong>mysql.env<\/strong> file from a previous example:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a80b859\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a80b859\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"437\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment-1.png\/w=1024,h=1024,fit=scale-down\" alt=\"Sample environment file for MySQL database connection details, including a top-line comment.\" class=\"wp-image-128436\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment-1.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment-1.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment-1.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment-1.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/mysql_env_with_comment-1.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>On paper, it has all you need to connect to a MySQL host, and all you need are the exact values to feed to the mysql command. But manually typing or hardcoding them into a script isn&rsquo;t ideal. Instead, you can combine <strong>cut <\/strong>with other commands to extract and use only the values you need.<\/p><ol class=\"wp-block-list\">\n<li>Create a new script file:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">touch connect.sh\nchmod +x connect.sh<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Open the file with your preferred editor. For this example, we will use nano:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nano connect.sh<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Insert the following values:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\nDB_HOST=$(grep DB_HOST mysql.env | cut -d '=' -f 2)\nDB_PORT=$(grep DB_PORT mysql.env | cut -d '=' -f 2)\nDB_USER=$(grep DB_USER mysql.env | cut -d '=' -f 2)\nDB_PASSWORD=$(grep DB_PASSWORD mysql.env | cut -d '=' -f 2)\nDB_NAME=$(grep DB_NAME mysql.env | cut -d '=' -f 2)<\/pre><p>You use a combination of <strong>grep <\/strong>to fetch the exact line you need and <strong>cut <\/strong>to return the value, which gets stored as a shell variable.<\/p><ol start=\"4\" class=\"wp-block-list\">\n<li>To test this, append the following string:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo 'Connection string is: mysql -h ' $DB_HOST ' -P ' $DB_PORT ' -u ' $DB_USER '&nbsp; -p ' $DB_PASSWORD $DB_NAME<\/pre><p>The above command will output the parsed string in your terminal. Here&rsquo;s how the full script looks:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a80c794\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a80c794\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"279\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/scripting_with_cut.png\/w=1024,h=1024,fit=scale-down\" alt=\"Image of the connect.sh script which was written in previous steps, displaying how cut can be utilized in a bash script.\" class=\"wp-image-128437\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/scripting_with_cut.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/scripting_with_cut.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/scripting_with_cut.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/scripting_with_cut.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/scripting_with_cut.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"5\" class=\"wp-block-list\">\n<li>Save the file with <strong>CTRL+X &rarr; Y &rarr; Enter<\/strong>.<\/li>\n<\/ol><p>Now, if you execute the <strong>connect.sh <\/strong>script, you&rsquo;ll get the full connection string for your database:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a5892a80d45c\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a5892a80d45c\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1849\" height=\"120\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=1024,h=1024,fit=scale-down\" alt=\"The output of the connect.sh script defined above which returns parsed out values taken from the mysql.env file to form a full connection string to a MySQL server.\" class=\"wp-image-128438\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=1849,fit=scale-down 1849w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/05\/connect_sh_output.png\/w=1536,fit=scale-down 1536w\" sizes=\"auto, (max-width: 1849px) 100vw, 1849px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>You can also replace the echo statement with:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mysql -h $DB_HOST -P $DB_PORT -u $DB_USER -p $DB_PASSWORD $DB_NAME<\/pre><p>This way, instead of giving you the connection string, it will automatically attempt to connect.<\/p><p>The <strong>cut <\/strong>command is most powerful when used in combination with other commands. It&rsquo;s a versatile tool for parsing data needed for automation.<\/p><h2 class=\"wp-block-heading\" id=\"h-conclusion\"><strong>Conclusion<\/strong><\/h2><p>The cut command in Linux is a simple but effective tool for working with structured data. It&rsquo;s fast, reliable, and easy to use in scripts or one-liners. When the structure is consistent, <strong>cut <\/strong>often does the job quicker than heavier tools.<\/p><p>If you&rsquo;re comfortable using the Linux terminal and want to automate parts of your workflow, you&rsquo;ll find <strong>cut <\/strong>to be very useful &ndash; and even more so when combined with other Linux commands.<\/p><h2 class=\"wp-block-heading\" id=\"h-linux-cut-command-faq\"><strong>Linux cut command FAQ<\/strong><\/h2><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1747637438866\"><h3 class=\"schema-faq-question\"><strong>What is the Linux cut command used for?<\/strong><\/h3> <p class=\"schema-faq-answer\">The <strong>cut <\/strong>command in Linux extracts specific sections from each line of text in a file or input stream. You can select bytes, characters, or fields based on delimiters. It&rsquo;s commonly used to pull out columns from CSVs, config files, logs, or command output in scripts and one-liners.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1747637444645\"><h3 class=\"schema-faq-question\"><strong>How do I cut specific fields from a file using the cut command?<\/strong><\/h3> <p class=\"schema-faq-answer\">To cut specific fields, use the <strong>-f<\/strong> option along with <strong>-d <\/strong>to set the delimiter. For example, <strong>cut -d &lsquo;,&rsquo; -f 2 file.csv<\/strong> extracts the second field from a comma-separated file. You can also use<strong> -f<\/strong> with a range or list, as with <strong>-f 1,3<\/strong>, to extract multiple fields.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1747637478295\"><h3 class=\"schema-faq-question\"><strong>Can I use multiple delimiters with the cut command?<\/strong><\/h3> <p class=\"schema-faq-answer\">No, <strong>cut<\/strong> only supports a single delimiter at a time, but you can set an output delimiter that differs from the one you&rsquo;ve identified with the <strong>-d <\/strong>flag. If you need to use multiple input delimiters, pre-process your file with a command like <strong>sed<\/strong> to ensure all the delimiters match.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>When working with Linux, you&rsquo;ll often deal with structured text data in a file, output from a command, or characters generated by a script. Most of the time, you don&rsquo;t need all of it. You might just want a specific column, a few characters, or one particular part of each line. That&rsquo;s where the cut [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/linux-cut-command\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":515,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to use the Linux cut command","rank_math_description":"Learn how to use the Linux cut command to extract fields, bytes, and characters with clear examples and explanations.","rank_math_focus_keyword":"linux cut command","footnotes":""},"categories":[22644],"tags":[],"class_list":["post-128415","post","type-post","status-publish","format-standard","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/linux-cut-command","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/linux-cut-command","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/linux-cut-command","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/linux-cut-command","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/linux-cut-command","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/linux-cut-command","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/linux-cut-command","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/linux-cut-command","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/128415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/515"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=128415"}],"version-history":[{"count":7,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/128415\/revisions"}],"predecessor-version":[{"id":143298,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/128415\/revisions\/143298"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=128415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=128415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=128415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}