Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed remove all content in line after \t

Tags:

sed

awk

I have o/p like

19599 user  20   0  120m  32m 4260 S 14.0  5.3   3:21.13 app.out  \t Wed Jun  8 09:31:06 UTC 2011
19599 user  20   0  120m  32m 4260 S 14.0  5.4   3:21.61 app.out  \t Wed Jun  8 09:31:12 UTC 2011
19599 user  20   0  121m  32m 4260 S 12.0  5.4   3:22.31 app.out  \t Wed Jun  8 09:31:17 UTC 2011

I want to remove all character starting from \t in the line. How can I do that with sed?

I tried with awk -F t '{print $1}' but it removing t from app.out .

I want o/p like

19599 user  20   0  120m  32m 4260 S 14.0  5.3   3:21.13 app.out
19599 user  20   0  120m  32m 4260 S 14.0  5.4   3:21.61 app.out
19599 user  20   0  121m  32m 4260 S 12.0  5.4   3:22.31 app.out

If I wrote the awk like this:

 awk -F t '{print $1"t"}'

it works fine, but it is only a work around. How can I remove all character starting from \t in the line till end of line?

like image 782
Vivek Goel Avatar asked Oct 26 '25 01:10

Vivek Goel


1 Answers

If the output contains the two characters backslash and 't', then you use:

sed 's/ *\\t.*//'

This removes the blanks leading up to the two characters, the backslash and the 't', plus everything after them.

If the output contains a tab character, then you need to replace the '\\t' with an actual tab character.

like image 85
Jonathan Leffler Avatar answered Oct 29 '25 07:10

Jonathan Leffler