How to delete columns?

I created the following text file below:

fe120b99164f151b28bf86afa6389b22 -rw-r--r-- 1 joey joey 186 2010-03-14 19:26 Descript.txt
41705ea936cfc653f273b5454c1cdde6 -rw-r--r-- 1 joey joey  30 2010-03-14 20:29 listof.txt
0e25cca3222d32fff43563465af03340 -rw-r--r-- 1 joey joey  28 2010-03-14 23:35 sedexample.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-02-16 15:11 test1.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-02-16 15:11 test2.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-02-16 15:11 test3.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-02-16 15:11 test4.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-02-16 15:11 test5.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-02-16 15:11 test6.txt
f5c7f1856249d0526be10df5bd5b895a -rw-r--r-- 1 joey joey  26 2010-03-13 14:13 testingfile.txt
d41d8cd98f00b204e9800998ecf8427e -rw-r--r-- 1 joey joey   0 2010-03-15 00:28 uniquelist.txt

Basically, I would like to get rid of the access, amount, user and group columns. In other words, I want to get rid of columns 3,4,5. I tried to use the slit to keep the columns I need and have “like my separator, however due to the file size digits, it messed up using the“ space ”as the separator. Any advice would be much appreciated! Oh, just add I would like to save the output as another text file. Thank you very much!

+3
source share
8 answers

What does your team look like cut?

$ cut -d" " -f1,6- file
fe120b99164f151b28bf86afa6389b22 186 2010-03-14 19:26 Descript.txt
41705ea936cfc653f273b5454c1cdde6  30 2010-03-14 20:29 listof.txt
0e25cca3222d32fff43563465af03340  28 2010-03-14 23:35 sedexample.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-02-16 15:11 test1.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-02-16 15:11 test2.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-02-16 15:11 test3.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-02-16 15:11 test4.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-02-16 15:11 test5.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-02-16 15:11 test6.txt
f5c7f1856249d0526be10df5bd5b895a  26 2010-03-13 14:13 testingfile.txt
d41d8cd98f00b204e9800998ecf8427e   0 2010-03-15 00:28 uniquelist.txt

redirect to a new file as needed.

Or awk

$ awk '{$2=$3=$4=$5="";gsub(/ +/," ")}1' file
fe120b99164f151b28bf86afa6389b22 186 2010-03-14 19:26 Descript.txt
41705ea936cfc653f273b5454c1cdde6 30 2010-03-14 20:29 listof.txt
0e25cca3222d32fff43563465af03340 28 2010-03-14 23:35 sedexample.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-02-16 15:11 test1.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-02-16 15:11 test2.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-02-16 15:11 test3.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-02-16 15:11 test4.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-02-16 15:11 test5.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-02-16 15:11 test6.txt
f5c7f1856249d0526be10df5bd5b895a 26 2010-03-13 14:13 testingfile.txt
d41d8cd98f00b204e9800998ecf8427e 0 2010-03-15 00:28 uniquelist.txt
+4

.

cut --delimiter=' ' --fields=3-5 --complement

C, popen.

, , cut . tr col -x.

+3

awk '{print $1 $6 $7 $8 $9;}'?

+3

C? , perl awk.

awk '{print $1 $6 $7 $8 $9}' file.txt
+2

, .

, :

sed "s/ \+/ /g" input_file | cut -d' ' -f-2,6-

, command > file.

0

awk '{print $1 $6 $7 $8 $9}' file.txt, :

fe120b99164f151b28bf86afa6389b221862010-03-1419: 26Descriptions.txt 41705ea936cfc653f273b5454c1cdde6302010-03-1420: 29listofnumbers.txt 0e25cca3222d32fff43563465af03340282010-03-1423: 35sedexample.txt d41d8cd98f00b204e9800998ecf8427e02010-02-1615: 11test1.txt d41d8cd98f00b204e9800998ecf8427e02010-02-1615: 11test2.txt d41d8cd98f00b204e9800998ecf8427e02010-02-1615: 11test3.txt d41d8cd98f00b204e9800998ecf8427e02010-02-1615: 11test4.txt d41d8cd98f00b204e9800998ecf8427e02010-02-1615: 11test5.txt d41d8cd98f00b204e9800998ecf8427e02010-02-1615: 11test6.txt f5c7f1856249d0526be10df5bd5b895a262010-03-1314: 13testingfile.txt d41d8cd98f00b204e9800998ecf8427e02010-03-1500: 28uniquelist.txt

All columns are combined into one, which is not ideal for me, since I will use uniq alone this at some point. Thank you for your help!

0
source

Try opening them in excel with a space as a separator, delete it there. See if it works.

-1
source

Source: https://habr.com/ru/post/1736938/


All Articles