Unix command to remove everything after first column

arsenal picture arsenal · Jan 15, 2013 · Viewed 25.1k times · Source

I have a text file in which I have something like this-

10.2.57.44      56538154    3028
120.149.20.197  28909678    3166
10.90.158.161   869126135   6025

In that text file, I have around 1,000,000 rows exactly as above. I am working in SunOS environment. I needed a way to remove everything from that text file leaving only IP Address (first column in the above text file is IP Address). So after running some unix command, file should look like something below.

10.2.57.44
120.149.20.197
10.90.158.161

Can anyone please help me out with some Unix command that can remove all the thing leaving only IP Address (first column) and save it back to some file again.

So output should be something like this in some file-

10.2.57.44
120.149.20.197
10.90.158.161

Answer

Mudassir Hasan picture Mudassir Hasan · Jan 15, 2013

If delimiter is space character use

 cut -d " " -f 1 filename

If delimiter is tab character , no need for -d option as tab is default delimiter for cut command

cut -f 1 filename

-d Delimiter; the character immediately following the -d option is the field delimiter .

-f Specifies a field list, separated by a delimiter