Treat Command Output as a File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Treat Command Output as a File
# 8  
Old 10-01-2014
What OS are you on, does your system have /dev/fd/?

If so, you could consider using bash or ksh shells. Basically if the <(command) works your system supports it.

This is not very portable and is typically avoided because of this. However if you know your only going to run the script on known platform(s).
This User Gave Thanks to Chubler_XL For This Post:
# 9  
Old 10-01-2014
Quote:
Originally Posted by Chubler_XL
What OS are you on, does your system have /dev/fd/?

If so, you could consider using bash or ksh shells. Basically if the <(command) works your system supports it.

This is not very portable and is typically avoided because of this. However if you know your only going to run the script on known platform(s).
Code:
$ cd /dev/fd/
sh: /dev/fd/:  not found.
$ uname -a
HP-UX system1 B.11.31 U ia64 0189138652 unlimited-user license
$ echo $SHELL
/sbin/sh
$

Smilie
# 10  
Old 10-01-2014
echo $0
This User Gave Thanks to vgersh99 For This Post:
# 11  
Old 10-01-2014
Quote:
Originally Posted by vgersh99
echo $0
Code:
$ echo $0
-sh

---------- Post updated at 01:26 PM ---------- Previous update was at 01:22 PM ----------

I've read somewhere that I can use `! <command> ` for Bourne instead.

But the output is not what I expect. So I just would some clarification here.

Does this BASH shell script
Code:
grep -vxFf incomplete.list <(cut -c 1-25 source.list

equivalent to this BOURNE shell script
Code:
grep -vxFf incomplete.list `! cut -c 1-25 source.list`

Thank you.
# 12  
Old 10-01-2014
For HPUX /sbin/sh is a POSIX-compliant shell. POSIX does not require process substitution, which is what you are asking for. Out of the box 11i HPUX has /bin/ksh which does support it.

This explains it:
Process substitution [Bash Hackers Wiki]

Whether or not it is allowed on a given OS depends on the existence
Code:
 /dev/fd

If you get a return from
Code:
ls /dev/fd

ex:
Code:
$>  ls /dev/fd
0 1 2 3 5 9

then process substitution will work in ksh.

To enable ksh, put a shebang on the first line of a script in the leftmost column:
Code:
#!/bin/ksh

This User Gave Thanks to jim mcnamara For This Post:
# 13  
Old 10-01-2014
No, it is not. The first, although missing a closing parenthesis, is called "process substitution" and offers cut's results as a stream on stdin for grep.
The second offers cut's results as a list of parameters (i.e. file names) to grep . The "!" will invert cut's exit code in sh, it will perform history expansion in bash.
This User Gave Thanks to RudiC For This Post:
# 14  
Old 10-01-2014
Thanks Jim & Rudic.

Btw, I just noticed that in reality this code should be the other way around actually:
Code:
cut -c 1-25 source.list | grep -vxFf complete.list

that is I have to find the missing item from source.list against complete.list

So, is it possible without having to create a new file to get the cut -c 1-25 source.list part?

Thanks.

---------- Post updated at 10:26 AM ---------- Previous update was at 09:23 AM ----------

At the moment, I use this command to avoid multiple lines command:
Code:
cut -c 1-25 source.list > source.temp && grep -vxFf source.temp complete.list > missing.list && rm -f source.temp

But the issue here is, the rm -f source.temp is only executed whenever the missing.list is not 0 in size.

Please help.

Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. Red Hat

Command understanding the output file destination in case of standard output!!!!!

I ran the following command. cat abc.c > abc.c I got message the following message from command cat: cat: abc.c : input file is same as the output file How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Discussion started by: ravisingh
3 Replies

3. Shell Programming and Scripting

[Perl] Same entries in file, but treat them different.

Hi, I could use some help with a program that examines a log file. It should output the duration of the steps in minutes. My problem is that there is no end of a step given, only the begin of a next step. Actually the problem is that this line comes 3 times, but marks 3 different events: ... (6 Replies)
Discussion started by: ejdv
6 Replies

4. Shell Programming and Scripting

to take the output of a command to a file

hi , i am using iostat -nmzx 1 | awk '{ print $4 }' command to get the i/o rates of disks. but i want command output in a file , how can i capture , this is some what difficult because command output is keep on changing , any way i have to get total output of the command . please help me .... (1 Reply)
Discussion started by: shankr3
1 Replies

5. Shell Programming and Scripting

Help me to command to output file format.

Dear Master. Help me to command to out put. Ex log. "<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom> <txid>17251032659</txid> <authentication> <user>admin</user> <password>Amrduoi</password> </authentication> <destination> <msisdn>1111111</msisdn> ... (2 Replies)
Discussion started by: ooilinlove
2 Replies

6. UNIX for Dummies Questions & Answers

getting Output of ls command in a file

Hi I am trying to get the output of ls into a file with names seaparated with comma and no spaces. Here is the content of my dir: ls file1 file2 file3 file4this is what I tried: ls -m > list.txtthe file 'list.txt' looks like: file1, file2, file3, file4, list.txtI... (25 Replies)
Discussion started by: jdhahbi
25 Replies

7. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. UNIX for Dummies Questions & Answers

Output of command to 2 separate file?

How would I echo the same results to two files? One is a running log, and the other is a cache, or sort. echo "Hello World" >> /Logs/File1 & /tmp/file2 I would just copy it from one place to the other, but the Log keeps history, where I want the /tmp to hold only stuff per session. I tried... (2 Replies)
Discussion started by: TheCrunge
2 Replies

10. Shell Programming and Scripting

awk - treat multiple delimiters as one

Is there anyway to get awk to treat multiple delimiters as one? Particularly spaces... (6 Replies)
Discussion started by: peter.herlihy
6 Replies
Login or Register to Ask a Question