Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App

col command in Linux with Examples

Last Updated : 18 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The col utility of Linux is excellent at stripping any reverse line feeds and instead replacing the whitespace characters with tabs wherever possible. They find it particularly handy when processing output from such commands as `nroff` and `tbl`. The `col` utility reads data from the standard input and writes it to the standard output. Thus, it is a convenient utility while processing text on pipelines.

Syntax

col [-bfhpx] [-l num]

Basic Example

Construct an example file called `sample.txt` with a message including reverse line feeds and whitespace:

Basic Example
sample.txt data

We then run the basic 'col' command without options:

cat sample.txt | col > output.txt

This command inputs and removes reverse line feeds, using optimized whitespace.

2024-10-14_14-21
Basic col command example

Key Options of col command

Option

Description

-b

do not output backspaces

-f

allow forward half line feeds

-h

do not output multiple spaces instead of tabs

-l num

buffer at least num lines in memory

-p

pass unknown control sequences unchanged

-x

output multiple spaces instead of tabs

1. -b (No Backspaces)

This option does not show the backspaces, printing instead only the last character written to each column position.

cat sample.txt | col -b > output_no_backspace.txt
-b (No Backspaces)

2. -f (Forward Half Line Feeds)

This option allows half line feeds to be passed through, which may be useful for some formats of text.

cat sample.txt | col -f > output_half_line_feeds.txt
 -f (Forward Half Line Feeds)

3. -h (Do Not Expand Multiple Spaces)

This option will not produce multiple spaces, but instead it will use tabbing where possible:

cat sample.txt | col -h > output_no_multiple_spaces.txt
-h Do Not Expand Multiple Spaces

4. -l (num Buffer Lines)

This option specifies the number of lines to buffer in memory; the default is 128 lines.

cat sample.txt | col -l 256 > output_buffered.txt
-l (num Buffer Lines)

5. -p: Pass Unknown Control Sequences

This option allows unknown control sequences to pass without change, instead of being filtered.

cat sample.txt | col -p > output_pass_control.txt

6. -x: Output Multiple Spaces

This option prints multiple spaces for every tab. This could be necessary for certain types of layout format.

cat sample.txt | col -x > output_multiple_spaces.txt
2024-10-14_14-32

Conclusion

The col command is a general-purpose tool under the Linux text processing toolkit. It is quite indispensable when formatting complex text such as man pages or at any other point of output in different text formatting tools. Further, knowing its different options and usage will enable you to control line feeds, whitespaces, and control characters in your text processing workflows effectively.


R

rahulkumarmandal
Improve
Article Tags :
  • Linux-Unix
  • linux-command
  • Linux-misc-commands

Similar Reads

    chattr and lsattr commands in Linux with examples
    In the world of Linux, managing file permissions and attributes is crucial for maintaining a secure and organized system. Two powerful commands that help control file and directory attributes are 'chattr' and 'lsattr'. These commands are essential for administrators and advanced users who need to pr
    8 min read
    chfn command in Linux with examples
    'chfn' command in Linux allows you to change a user's name and other details easily. 'chfn' stands for Change finger. Basically, it is used to modify your finger information on Linux system. This information is generally stored in the file '/etc/passwd' that includes user's original name, work phone
    3 min read
    chgrp command in Linux with Examples
    The `chgrp` command in Linux is used to change the group ownership of a file or directory. All files in Linux belong to an owner and a group. You can set the owner by using “chown” command, and the group by the "chgrp" command. Syntax of `chgrp` command in Linuxchgrp [OPTION]… GROUP FILE… chgrp [OPT
    3 min read
    chkconfig command in Linux with Examples
    'chkconfig' command is used to list all available services and view or update their run level settings. In simple words it is used to list current startup information of services or any particular service, update runlevel settings of service, and adding or removing service from management. Here we’l
    3 min read
    How to Make Script Executable in Linux | chmod Command
    In Unix operating systems, the chmod command is used to change the access mode of a file. The name is an abbreviation of change mode. Which states that every file and directory has a set of permissions that control the permissions like who can read, write or execute the file. In this the permissions
    7 min read
    How to Change File Ownership in Linux | chown Command
    In the Linux operating system, file ownership is a crucial aspect of system security and user management. The chown command, short for "change owner," is a powerful tool that allows users to change owner of file in Linux. This command is particularly useful in scenarios where administrators need to
    9 min read
    chpasswd command in Linux with examples
    chpasswd command is used to change password although passwd command can also do same. But it changes the password of one user at a time so for multiple users chpasswd is used. Below figure shows the use of passwd command. Using passwd we are changing the password of the guest user. Here first you ha
    2 min read
    chroot command in Linux with examples
    The 'chroot' command in Linux and Unix-like systems is used to change the root directory for the current running process and its child processes. This change creates a restricted environment, often referred to as a "chroot jail" or "jailed directory," where processes are limited to accessing only fi
    3 min read
    chrt command in Linux with examples
    'chrt' command in Linux is known for manipulating the real-time attributes of a process. It sets or retrieves the real-time scheduling attributes of an existing PID, or runs the command with the given attributes. 'chrt' can help optimize process management in a Linux system, especially for applicati
    4 min read
    chsh command in Linux with examples
    chsh command in Linux is used to change the user's login shell(currently login shell). Shell is an interactive user interface with an operating system and can be considered an outer layer of the operating system. The bash shell is one of the most widely used login shells in Linux. This command allow
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences