Comment on Parsing JSON in Forty Lines of AwkparentComments−shawn_w1yAs long as you don't mind the extra space in the middle.−chaps1yOften times I don't! Entirely depends on what I'm doing. #1 thing off the top of my head is to remove That One Column that's a bajillion characters long that makes exploratory analysis difficult.−saghm1yI wonder if it's possible to encode the backspace character in the replacement string?−ZoomZoomZoom1yNo problem, there's \b. echo "one two three four five" | awk '{$3="\b"; print}' Inserts the backspace character (^H), which you can then remove with [global] substitution: awk '{$3="\b"; sub(/\32\b/, ""); print}' You can, of course, use an arbitrary sentinel value for the field to be deleted. Should work in gawk and BWK awk.−fragmede1yif you do: sed 's/ / /g'−lucb1e1yOr sticking with awk, I have this bash alias to remove excess whitespace that is just: awk '{$1=$1};1'−fuzztester1ywhat does the 1 at the end do? make awk print all lines? I'm a bit rusty with my awk.−thrwwy92341yIt’s a condition. 1 is true-ish, so it’s a condition that is always true. The default action in awk is print, so it’s the same as: '{$1=$1}1{print}' Or the same as '{$1=$1}{print}' Since the default condition is true. But 1 is shorter than {print}.
Comments
As long as you don't mind the extra space in the middle.
Often times I don't! Entirely depends on what I'm doing. #1 thing off the top of my head is to remove That One Column that's a bajillion characters long that makes exploratory analysis difficult.
I wonder if it's possible to encode the backspace character in the replacement string?
No problem, there's \b.
Inserts the backspace character (^H), which you can then remove with [global] substitution: You can, of course, use an arbitrary sentinel value for the field to be deleted. Should work in gawk and BWK awk.if you do:
Or sticking with awk, I have this bash alias to remove excess whitespace that is just:
what does the 1 at the end do? make awk print all lines? I'm a bit rusty with my awk.
It’s a condition. 1 is true-ish, so it’s a condition that is always true. The default action in awk is print, so it’s the same as:
Or the same as Since the default condition is true. But 1 is shorter than {print}.