0

Using the finch IRC client, I copy/pasted a list of names to names.txt for processing.

Basically, the names are seperated by spaces. Many of the names will have special characters like "/" or "%" in them. Apparently. By "name" here I mean IRC handle, which is, presumably, a single word.

I tried using xargs to pull out a "list" of names as xargs names.txt but the command just hung.

Can I use xargs for this? If so, how?


sample input:

word1 word2 word3

sample output

word1
word2
word3

pardon for overcomplicating the question.

  • 1
    xargs either reads from standard input (xargs < names.txt) or from a file given as an argument to the -a option (xargs -a names.txt) – steeldriver Jul 19 '21 at 01:09
  • ah, xargs < names.txt echoes out the file but doesn't seperate each word on a new line as was looking for. Basically, a "list" of all the "words" in the file in a regex way. – Nicholas Saunders Jul 19 '21 at 01:13

1 Answers1

1

You can tell xargs to process at most num arguments per call using -n max-args

   -n max-args, --max-args=max-args
          Use  at  most  max-args  arguments per command line.  Fewer than
          max-args arguments will be used if the size (see the -s  option)
          is  exceeded, unless the -x option is given, in which case xargs
          will exit.

So

xargs -n 1 < names.txt

(arguments are separated by whitespace by default).

However that's somewhat subverting the intent of xargs - you might consider using something like tr -s '[:space:]' '\n' < names.txt instead.

steeldriver
  • 81,074