0

Say I have a file of filenames like this:

requests.log
responses.log
resources used.log

and I want to view all of those files. I'd be tempted to do:

$ vi `cat /tmp/list`

but that winds up opening the files "requests.log", "responses.log", "resources", and "used.log" which is not what I want.

I tried

$ cat /tmp/list | xargs -L 99 vi

but that results in the error message "Warning: input not from a terminal"

I've tried editing the file and quoting each of the individual lines, but that was no help either.

Is there a way to do this short of writing some sort of front-end script?

Edward Falk
  • 1,913
  • 15
  • 14
  • Adding on: this is on MacOS; the xargs command has no "-a" option. – Edward Falk May 05 '21 at 00:23
  • That worked, but I was hoping for something simple enough to remember. – Edward Falk May 05 '21 at 00:32
  • 1
    To have command substitution 'wordsplit' only at newlines, do `(IFS=$'\n'; vi $(cat list))`. But if the lines in the file have trailing spaces, as your selfanswer implies, this will retain those spaces and the open will fail, so do `(IFS=$'\n'; vi $(sed 's/ *$//' list))`. On ancient shells you may need `IFS=''` which looks ugly but works. – dave_thompson_085 May 05 '21 at 06:05
  • Thanks; good answer. My lines don't have trailing spaces; the rsplit() is to remove the trailing newlines. – Edward Falk May 07 '21 at 17:29
  • 1
    Also see [How to edit a list of generated files whose names contain spaces](https://unix.stackexchange.com/q/597764/100397) – roaima May 07 '21 at 18:30

1 Answers1

0

Here's what I wound up writing. It works, but it's kind of a non-answer since I was hoping to do this without writing a front end.

#!/usr/bin/env python3

usage = """
Read arguments from a file, one per line, then execute the given
command.

usage:      lineargs <filename> <cmd> [args]
"""

import os
import sys

argfilename = sys.argv[1]        # Get arguments from this file, one per line
cmd = sys.argv[2:]               # The command and additional arguments

args = open(argfilename, "r").read().splitlines()

cmd.extend(args)
os.execvp(cmd[0], cmd)

I didn't bother with error checking, etc. This is just a one-off script.

Edward Falk
  • 1,913
  • 15
  • 14