Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing columns in text file with Bash?

Tags:

linux

bash

unix

I have a to write a script that remove the Idle column from the output of finger.

>finger
Login    Name                 TTY  Idle  Login  Time   Office  Phone
Billy    Billy Howard        *con  6:55  Fri    19:03
Billy    Billy Howard         s00     5  Fri    19:11
Billy    Billy Howard         s00        Sat    00:27

I tried remove the extra spaces with tr and then using cut with a delimiter of a space to remove the column, but since Idle can have no value I sometimes get the wrong value since tr delimited the spaces were the idle time should be... Does anyone know how I can remove the Idle column?

like image 820
Homeschooldev Avatar asked Dec 13 '22 05:12

Homeschooldev


1 Answers

This might work for you:

finger |  sed 's/\(.\{35\}\)...../\1/'

or this:

finger |  cut --complement -c36-40 
like image 113
potong Avatar answered Dec 21 '22 08:12

potong