Unwanted blank after word deletion
Have: a file of lines containing blank-delimited words, such as ...
Code:
one two three four five Code:
one three four five Code:
cut -d" " -f1,3- Code:
awk '{$2=""; print}' Code:
one three four five Daniel B. Martin |
Code:
{ for (i=1; i<NF; i++) |
Changed it a bit. More compact, and removed trailing space.
|
How about:
Code:
awk 'sub(" "$2,"")' file |
@grail
Nice trick ! Must read about awk functions. |
Quote:
Daniel B. Martin |
Hi.
grail's approach have this little problem: Code:
$ echo 'one two three four three five' | awk '{sub(" "$5, "")} 1' I myself yet to discover an elegant way to do this though. EDIT: Code:
$ echo 'one two three four five' | awk '{$2=""; $0=$0; $1=$1} 1' Code:
$ echo 'one two three four five' | awk '{$2=""; gsub(" +", " ")} 1' BTW, just for fun, this also prints on a terminal what you want :) Code:
$ echo 'one two three four five' | awk '{$2="\b"} 1' |
All times are GMT -5. The time now is 05:37 AM. |