User Tools

Site Tools


bash:cut:cut_using_characters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
bash:cut:cut_using_characters [2019/12/12 22:31] peterbash:cut:cut_using_characters [2021/01/26 16:05] (current) – removed peter
Line 1: Line 1:
-====== BASH - cut - Cut using Characters ====== 
- 
-Cut a section of text based on characters. 
- 
-Useful when handling large file processing tasks. 
- 
----- 
- 
- 
-===== Cut a Single Character from the Input Stream ===== 
- 
-<code bash> 
-echo "cutting text from input" | cut -c 1 
-</code> 
- 
-The above command cuts the first character from the standard input and displays it in the terminal. 
- 
-In this case, it is “c“.  
- 
----- 
- 
-===== Cut Specific Characters from the Input Stream ===== 
- 
-<code bash> 
-echo "cutting text from input" | cut -c 1,3 
-</code> 
- 
-This command will cut only the first and third characters of the input string and show them. 
- 
-<WRAP important> 
-Remember not to exceed the character limit of your string. 
-</WRAP> 
- 
----- 
- 
-===== Cut a Range of Characters from the Input Stream ===== 
- 
-<code bash> 
-echo "cutting text from input" | cut -c 1-12 
-</code> 
- 
-Cuts characters from the first position to the twelfth position. 
- 
-The result will be “cutting text“. 
- 
----- 
- 
-===== Cut a Single Character from a Text file ===== 
- 
-<code bash> 
-cut -c 1 test.txt 
-</code> 
- 
-Displays only the first characters of each of the five rows of our file test.txt. 
- 
-It is equivalent to the command <code bash>cat test.txt | cut -c 1</code> and provides the same result as we would get when using the byte flag. 
- 
----- 
- 
-===== Cut Specific Characters from the a File ===== 
- 
-<code bash> 
-cut -c 7,10 test.txt 
-</code> 
- 
-Cuts only the seventh and tenth characters of each five rows. 
- 
-You can specify any character positions as long as they fall within the range of available characters. 
- 
----- 
- 
-===== Cut a Range of Characters a Text File ===== 
- 
-<code bash> 
-cut -c 1-12 test.txt 
-</code> 
- 
-Outputs the first one to twelfth characters of each line in the test.txt file. 
- 
-The cut command in Unix behaves the same when cutting a range of characters and range of bytes. 
- 
----- 
- 
-===== Cut from a Specific Character to the End of the Input Stream ===== 
- 
-<code bash> 
-echo "cutting text from input" | cut -c 5- 
-</code> 
- 
-The above cut command will cut the text starting from the fifth byte to the end of the string. 
- 
-It can be beneficial when you need to cut from a specified character position until the end of the input stream. 
- 
-Simply change the value after b while keeping the trailing – on. 
- 
----- 
- 
-===== Cut from a Specific Character to the End of the File ===== 
- 
-<code bash> 
-cut -c 5- test.txt 
-</code> 
- 
-This command will start cutting each of the five rows of the test.txt file from their fifth character position and will finish after reaching the end of every line. 
- 
-The trailing hyphen(-) is mandatory for this kind of operation. 
- 
----- 
- 
-===== Cut a Specified Amount of Characters Starting from beginning of a string ===== 
- 
-<code bash> 
-echo "cutting text from input" | cut -c -5 
-</code> 
- 
-This command will only cut the first five character positions of our input. 
- 
-Remember to add the preceding hyphen(-) else the output will not be the same as you expect. 
- 
----- 
- 
-===== Cut from the First Character to a Specified Position from a File ===== 
- 
-<code bash> 
-cut -c -5 test.txt 
-</code> 
- 
-This cut command in Unix will cut the first five characters of each line from the file test.txt. 
- 
-Notice how the hyphen(-) is being used for the commands 21-24 in this list. 
- 
----- 
- 
-===== Cut the First few Characters in Alphabetical Order ===== 
- 
-<code bash> 
-cut -c 1-5 test.txt | sort 
-</code> 
- 
-Cuts the first five bytes of each row alphabetically. 
- 
-The sort command doesn’t require any options when sorting alphabetically. 
- 
----- 
- 
-===== Cut the First few Characters in Reverse Order ===== 
- 
-<code bash> 
-cut -c 1-5 test.txt | sort -r 
-</code> 
- 
-Cuts the first five characters from each row and will show them after sorting in reverse. 
- 
----- 
- 
-==== 
  
bash/cut/cut_using_characters.1576189898.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki