AWK experts - how would I code around this in awk...

Alex Janssen alex at ourwoods.org
Sun Feb 21 18:04:36 UTC 2010


Steve Flynn wrote:
>
> That's not a bad idea at all come to think of it.
>
> Remove ALL CR/LF's to make one honking big line and then spit it back
> out in chunks of 'n'.
>
> Definitely food for thought. I can feel some playing around on my
> laptop happening on the train home this afternoon... cheers! :)
>   
I had to play around with it to test it and decided it should just be a 
filter to read stdin and write stdout.  Here's a working script:
**********script
#remove all CR's and LF's and reinsert LF's every n characters
if [ $# -lt 1 ]
then
  echo -e "\n$0\n  Removes all CR's and LF's and reinsert LF's every n 
characters\n  usage:\n    $0 n\nn=new line length\n  $0 reads from stdin 
and writes stdout"
  exit 0
fi
NEWLEN=$1
tr -d "\n\r"|
while read -n$NEWLEN LINE
do
 echo "$LINE"
done
exit 0
**********end script
If you need CR's change the echo line to read "echo -e "$LINE\r".

Alex

-- 
Ourwoods.org
 Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. - Albert Einstein (275)





More information about the ubuntu-users mailing list