Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a unix command line utilty for 'mapping' by line?

I have an input stream, and I want to "map" to output lines. For instance, if my input stream were the files nums, I'd want that this syntax

$ cat nums
9534
2343
1093
7023
$ cat nums | map ./myscript $0

would be equivalent to

$ echo 9534 | ./myscript
$ echo 2343 | ./myscript
$ echo 1093 | ./myscript
$ echo 7023 | ./myscript
like image 443
Robert Martin Avatar asked Mar 26 '12 23:03

Robert Martin


People also ask

What is map command in Linux?

The pmap command in Linux is used to display the memory map of a process. A memory map indicates how memory is spread out. Syntax: pmap [options] pid [...]

What are Unix maps?

map (default). This file is ASCII-text formatted, and can be modified with a standard text editor. However, this file should not be modified unless the administrator is instructed to do so by the cluster softwre service provider. If this configuration file is to be modified, the default /opt/rsct/cfg/unix.


1 Answers

I think xargs is the closest thing to your hypothetical map:

cat nums | xargs -n1 ./myscript

or

cat nums | xargs -n1 -J ARG ./myscript ARG

or

cat nums | xargs -I ARG ./myscript ARG

Unfortunately, xargs doesn't let you invoke things that read from stdin, so you'd have to rewrite your script to accept a command-line argument rather than reading from stdin.

like image 170
Kristopher Johnson Avatar answered Sep 19 '22 12:09

Kristopher Johnson