There are multiple ways of extracting the data that you require.
If you see each line as a number of fields delimited by a space, then the most basic tool you could use to solve your issue would be cut
:
$ cut -d ' ' -f 1,2,4,6 file
file.txt 4 11 102
file_1.txt 5 10 100
file_3_2.txt 0 10 100
This extracts the 1st, 2nd, 4th, and 6th space-delimited field from the file.
Similarly, with awk
:
$ awk '{ print $1,$2,$4,$6 }' file
file.txt 4 11 102
file_1.txt 5 10 100
file_3_2.txt 0 10 100
This is doing the same thing, but there's slightly more going into it. The awk
tool treats its input as a stream of records made up by fields. By default, a record is simply a line and a field is any non-blank text delimited by blanks (spaces or tabs, possibly more than one). The output is created, one record at a time (by default, a line at a time), and the fields are separated by a single space.
A slightly more involved approach would be to cut out the first field from the rest of the data, delete anything which is a letter in the rest of the data, and then paste the two together again.
$ paste -d ' ' \
<( cut -d ' ' -f 1 file ) \
<( cut -d ' ' -f 2- file | tr -s '[:alpha:]' '[ *]' )
file.txt 4 11 102
file_1.txt 5 10 100
file_3_2.txt 0 10 100
This is a bit inelegant though, because it reads the input twice. The tr
command used will change all alphabetical characters to spaces, and then "squeeze" (with -s
) any set of multiple consecutive spaces down into single spaces.
The paste
command gets two input streams and concatenates these line by line with a space character in-between them. The first stream is provided via a process substitution (<( ... )
) running a cut
command that extract only the first column from the data. The second stream is provided by another process substitution running cut
to extract all columns from column 2 on, and which then replaces alphabetical characters with spaces in these columns using tr
as just previously described.