Deutsch   English   Français   Italiano  
<v1pi7c$2b87j$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Chmelik <dchmelik@gmail.com>
Newsgroups: alt.comp.lang.awk,comp.lang.awk
Subject: printing words without newlines?
Followup-To: alt.comp.lang.awk,comp.lang.awk
Date: Sun, 12 May 2024 04:57:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <v1pi7c$2b87j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 12 May 2024 06:57:16 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dde441e1ae9f53564db448737d7214ef";
	logging-data="2466035"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19fMkXjaqbwNoki+B+MEmCarV4O8wSZOKo="
User-Agent: Pan/0.158 (Avdiivka; 6a11104e)
Cancel-Lock: sha1:ocv8NU5wbIsGaRQ6JdYUaOY1cPY=
Bytes: 2261

I'm learning more AWK basics and wrote function to read file, sort, 
print.  I use GNU AWK (gawk) and its sort but printing is harder to get 
working than anything... separate lines work, but when I use printf() or 
set ORS then use print (for words one line) all awk outputs (on FreeBSD 
UNIX 14 and Slackware GNU/Linux 15) is a space (and not even newline 
before shell prompt)... is this normal (and I made mistake?) or am I 
approaching it wrong?  I recall BASIC prints new lines, but as I learned 
basic C and some derivatives, I'm used to newlines only being specified...
------------------------------------------------------------------------
# print_file_words.awk
# pass filename to function
BEGIN { print_file_words("data.txt"); }

# read two-column array from file and sort lines and print
function print_file_words(file) {
# set record separator then use print
# ORS=" "
  while(getline<file) arr[$1]=$0
  PROCINFO["sorted_in"]="@ind_num_asc"
  for(i in arr) 
  {
    split(arr[i],arr2)
    # output all words or on one line with ORS
    print arr2[2]
    # output all words on one line without needing ORS
    #printf("%s ",arr2[2])
  }
}
------------------------------------------------------------------------
# sample data.txt
2 your
1 all
3 base
5 belong
4 are
7 us
6 to