Use of the PASTE command in a script file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of the PASTE command in a script file
# 8  
Old 02-05-2013
Quote:
Originally Posted by RudiC
bash provides many functionalities that sh does not, for instance "process substitution" that you use in your code sample.
You need to output to two files, and paste those, or you need to play dirty tricks, like
Code:
$ mkfifo J
$ { code1; } | paste - J &      # paste stdin and the FIFO; put in background
$ { code2; } > J                # print to FIFO
$ rm J

Generally, I don't consider using fifo's to be in any way dirty. However, the way you're using one here is unreliable. The successful completion of your approach depends on several factors:

1. The shell's execution environment. If job control is enabled, each background job runs in its own process group. Background process groups may not be able to write to the terminal.
2. Terminal settings. If tostop is enabled (see stty), writes to the terminal by a process not in the foreground process group triggers SIGTTOU signals to all processes in the process group.
3. Process signal masks. If the writing process is blocking or ignoring SIGTTOU, then the signal isn't sent to the process group.

The following approach could be stopped as soon as paste tries to write.
Code:
mkfifo f1

cat <<EOF | paste - f1 &
1
2
3
EOF

cat <<EOF >f1
a
b
c
EOF

For a more reliable approach, I would suggest using a second fifo:
Code:
mkfifo f1 f2

cat <<EOF >f1 &
1
2
3
EOF

cat <<EOF >f2 &
a
b
c
EOF

paste f1 f2


Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Paste command not working in shell script

Hai , When i use paste command in command prompt its giving expected output but not in the script. Below is the example. $cat file 1 2 3 $cat file1 4 5 6 $paste -d ':' file file1 1:4 2:5 3:6 but when i used the same command in script its giving the output as below : 1 2 3 (3 Replies)
Discussion started by: Subbu123
3 Replies

2. Shell Programming and Scripting

How do I use paste command in while condition??

there are lot of files where in mostly all the file contains 2columnsAl,1 Ail,13 Al,3 Al,1 Al,3 Al,2 Al,3 Al,1 Al,1 Al,1 My requirement is i wanted only the second column of every file as a column ony in the base file... I used paste command... but it is not helping as I'm using while... (7 Replies)
Discussion started by: nikhil jain
7 Replies

3. Shell Programming and Scripting

Using paste command every nth number of file

Hi, I want to use paste command in a loop that does it every 6 files. My sample files are like the ones below. 20010101.txt 20010106.txt 20010111.txt 20010116.txt 20010121.txt 20010126.txt 20010131.txt 20010205.txt 20010210.txt 20010215.txt 20010220.txt 20010225.txt 20010302.txt... (4 Replies)
Discussion started by: ida1215
4 Replies

4. Shell Programming and Scripting

Can't paste in command line.

Hello. I've made a simple script which asks the user to input a hash and then runs a command that replaces the variable $hash with what the user inserted. The ting is that when the programm asks for input I can't paste anything there..! any clues?? :wall: (8 Replies)
Discussion started by: louboulos
8 Replies

5. Shell Programming and Scripting

need help with cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (3 Replies)
Discussion started by: drew211
3 Replies

6. UNIX for Dummies Questions & Answers

paste command

input1 15 150 input2 x 10 100 input3 y 20 200 z 34 44 cmd paste -d "\t" input1 input2 input3 >>output output (1 Reply)
Discussion started by: repinementer
1 Replies

7. Shell Programming and Scripting

read file column and paste it in command

Hi Unix gurus I have a file containing 2 coloumns. I would like to do a script which reads the lines and executes a command like this: command <field1> parameters <field2> some more parameters Please let me know how you would do this without AWK, SED or any other mini language (for special... (5 Replies)
Discussion started by: BearCheese
5 Replies

8. Shell Programming and Scripting

Paste command issue

Problem with Paste command :) Hi All, i need small suggestion in my below script... i have output in .txt format like below file1.txt 01111111 02222222 03333333 file2.txt 230125 000012 000002 now i want to merge both the file in xls or csv formate now i am using the below... (2 Replies)
Discussion started by: Shahul
2 Replies

9. Shell Programming and Scripting

Perl script assistance; paste word into external command

I'm attempting to create a Perl script that will: Take the contents of the usernames.tmp file (usernames.tmp is created from an awk one-liner ran against /etc/passwd) Take one line at a time and pass it to the su command as a users name. This should go on until there is no more name to... (10 Replies)
Discussion started by: bru
10 Replies

10. UNIX for Advanced & Expert Users

paste command

I wonder if any body can help me with a command i am struggling with. I have a file with around 400 lines in, in a program i have it pulls out each line at a time so that data from the line can be cross referenced with another file. If it finds a match it pulls out a ocde from the second file, this... (5 Replies)
Discussion started by: mariner
5 Replies
Login or Register to Ask a Question