User Tools

Site Tools


ops102:using_cut_with_spaces

Differences

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

Link to this comparison view

Next revision
Previous revision
ops102:using_cut_with_spaces [2024/11/08 19:04] – created chrisops102:using_cut_with_spaces [2025/03/05 15:18] (current) chris
Line 15: Line 15:
  $ grep chris /etc/passwd|cut -d: -f 5  $ grep chris /etc/passwd|cut -d: -f 5
  Chris Tyler</code>  Chris Tyler</code>
 +
 +The ''-d'' option specifies the delimter (separator) character (:) and the ''-f'' option specifies the field(s) to be cut out (5).
  
 ===== The Problem with Spaces ===== ===== The Problem with Spaces =====
Line 31: Line 33:
 The number of spaces between the fields varies, so that the fields line up vertically; for example, there are three spaces between fields 1 and 2 on the "bylee6" line, but only one space between fields 1 and 2 on the "aliakbar" line. The number of spaces between the fields varies, so that the fields line up vertically; for example, there are three spaces between fields 1 and 2 on the "bylee6" line, but only one space between fields 1 and 2 on the "aliakbar" line.
  
-The ''cut'' command expects only one delimiter between fields, so this presents a problem.+The ''cut'' command expects only one delimiter between fields, so this presents a problem. Notice that in the following output, the "bylee6" line is not cut properly because of the multiple spaces between field 1 and field 2: 
 + 
 +<code>$ w|tail -n +3 |cut -d " " -f2 
 + 
 +pts/1 
 +pts/2 
 +pts/3 
 +pts/4</code>
  
 ===== A Solution: ''tr'' ===== ===== A Solution: ''tr'' =====
ops102/using_cut_with_spaces.1731092651.txt.gz · Last modified: 2024/11/08 19:04 by chris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki