Sed remove all content in line after \t
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开发者_StackOverflow社区: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?
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.
It sounds like you want the first field in a tab-delimited text. You might try one of:
cut -d $'\t' -f 1
awk -F '\t' '{print $1}'
sed $'s/\t.*//'
The $''
syntax is used in bash (and ksh and zsh I believe) to more easily allow for embedding escape sequences in strings.
awk 'BEGIN { FS = "\t" } 1 == 1 {print $1}' file.name
Just pipe it through:
sed 's/\(.*\)\t.*/\1/'
精彩评论