Skip to main content
20 events
when toggle format what by license comment
Aug 6, 2023 at 18:52 comment added Andries I'm using zshell and found it very convient declcare a function such as: function trim() { awk '{$1=$1};1' } No need for file.
Mar 2, 2021 at 21:51 comment added access_granted On Solaris awk doesn't work, you need gawk.
May 16, 2020 at 2:55 comment added Aaron Franke How do I use this to trim files in-place?
Nov 21, 2017 at 23:15 comment added RonJohn Would this work as an alias, or would it be better as a function defined in /etc/profile?
Nov 29, 2016 at 12:48 comment added pronebird awk didn't work for me, still untrimmed spaces
Aug 11, 2016 at 18:35 comment added rubo77 @StéphaneChazelas: That doesn't seem to work. Please post it as a whole new answer, so we can see the line breaks as you intended. And we can discuss then if it works. (you mean a she-bang with just #! ?)
Aug 11, 2016 at 15:37 comment added Stéphane Chazelas note that it has to be on 2 lines, one for the she-bang, one for the code ({$1=$1};1).
Aug 11, 2016 at 14:45 comment added Stéphane Chazelas No need for bash, you can make it #! /usr/bin/awk -f {$1=$1};1. (beware of file names containing = characters though)
Dec 20, 2015 at 1:05 history edited rubo77 CC BY-SA 3.0
deleted 3 characters in body
Nov 20, 2015 at 16:26 comment added Jeff Clayton You can also add an alias in /etc/profile (or your ~/.bashrc or ~/.zshrc etc...) alias trim="awk '{\$1=\$1};1'"
May 27, 2015 at 21:27 history edited rubo77 CC BY-SA 3.0
added 17 characters in body
May 27, 2015 at 17:50 history edited rubo77 CC BY-SA 3.0
added 189 characters in body
May 27, 2015 at 14:52 comment added Stéphane Chazelas @don_crissti ...and/or has lines starting with - and followed by combinations of 1 or more e, E or n characters, and/or contains NUL characters. Also, a non-terminated line after the last newline will be skipped.
Dec 31, 2014 at 12:24 comment added don_crissti You'll have to use while read -r line to preserve backslashes and even then.... As to huge files / speed, really, you picked the worst solution. I don't think there's anything worse out there. See the answers on Why is using a shell loop to process text bad practice ? including my comment on the last answer where I added a link to a speed benchmark. The sed answers here are perfectly fine IMO and far better than read.
Dec 31, 2014 at 10:42 comment added rubo77 @don_crissti: could you comment a bit more?, which solution would be better fitting for huge files, and how could I modify my solution if the file contained backslashes?
Dec 31, 2014 at 1:31 comment added don_crissti Good luck if your file is huge and/or contains backslashes.
Dec 30, 2014 at 23:14 history edited rubo77 CC BY-SA 3.0
deleted 1 character in body
Feb 23, 2014 at 16:08 vote accept rubo77
May 27, 2015 at 17:45
Feb 23, 2014 at 16:07 history edited rubo77 CC BY-SA 3.0
deleted 1 characters in body
Nov 22, 2013 at 15:40 history answered rubo77 CC BY-SA 3.0