sonu Agarwal
sonu Agarwal

Reputation: 15

How to remove last repetitive word from text file in terminal

i have a txt file and want remove last tcp from that txt file .

$cat textfile
 886/tcp
 885/tcp
 884/tcp

i want textfile like Below

$cat textfile
 886
 885
 884

i don't have idea how resolve on terminal and thank you for your efforts

Upvotes: 1

Views: 26

Answers (1)

IMB
IMB

Reputation: 529

Try with the cut command:

cat textFile | cut -d '/' -f 1

Output:

886
885
884

Command flags explanation:

  • -d: lets you specify the delimiter to split on. In this case "/"

  • -f: lets you choose which substring of the split to choose. In this case we want the first substring so: 1

Upvotes: 1

Related Questions