Suppose I want to find the number of uniq lines in a file. I use the following command:
sort file1 | uniq -c | wc -l
But if for some reason sort fails, the above command returns 0 as the answer.
Why would sort fail ? sort makes use of directories /tmp or /var/tmp to store temporary files. So what I did is I renamed the temp dirs. And thats how sort failed..
After renaming the temp dirs:
Quote:
%> sort file1 | uniq -c | wc -l
sort: can't open /var/tmp/stmAAAEVayZ4.00000001: No such file or directory
0
So sort fails, but notice the 0 which is returned as the result.
Now, I have a program and I use popen() to execute the sort | uniq |wc command. What I want is, if sort fails, I should be able to catch it. But my program is not able to do so, because of the 0 returned as the result.
I have:
So even if sort fails, popen() writes a 0 to the stream pointed by fptr and uniqLines is always 0.
I guess what I am looking for is: When commands are piped, if any one command fails, the commands that follow should not execute...
No can do. Commands that are piped are all launched at the same time, so all those to the right have already been started before sort decides it's having a bad day.
You would need to execute the commands one after the other with intermediate files.
Hey, can you please tell me what does ksh -c do ? (or give some examples)
PIPESTATUS is only availablein bash and not in ksh.
I switched my shell to ksh and then executed:
/usr/bin/bash -c "echo ${PIPESTATUS[*]}" but that did not work.
Thanks porter !
(On 2nd thoughts it might not be a good thing to rely on a specific shell feature, hmm.. I guess I will have to write my own C program to implement PIPES (I am trying but its driving me crazyy, I shall post my queries soon :P )
In the below awk to add a sort by smallest to largest should it be added after the END? Thank you :).
BEGIN {
FS="*"
}
# Read search terms from file1 into 's'
FNR==NR {
s
next
}
{
# Check if $5 matches one of the search terms
for(i in s) {
if($5 ~ i) {
... (4 Replies)
I am trying to create a file (epilepsy70_average.txt) and then pipe that file into a sort and save a new file. The new file is sort.txt but as of know it is blank. I can create the file in one command and then sort it in another. Is the pipe not correct? Thank you :).
awk... (2 Replies)
Hi,
my os is SLES 10
from sort
iostat
as my output does not include rkB/s and wkB/s I probably have to adjust the key position, so
is the following iostat pipe to sort service request command correct?
oracle@vmc_stallite:~> iostat -x | sort -nrk11
sda 0.96 ... (4 Replies)
I have a file with three fields of data for example say we have
1420 $12.56 45
3456 $15.89 14
2341 $25.87 32
I need to use a command to show who is getting paid the highest amount to standard output. I am not sure if I should use a sort command or a copy and paste... (1 Reply)
Hello All,
Today i have been asking lots of question, hope to become good in scripting soon with all the wonderful advices i get. The question is i want to sort data a get uniq string from it. The code i am using to generate the output is:-
check_sun() {
for i in $SUN_PLATFORM
do
$ECHO... (0 Replies)
Hi All,
After Sorting directories and files i have got following output as below, now i only want the strings common in them, so the actual output should be as below in the bottom. How do i do that?
Thanks
-adsi
File to be modified:-
Common Components for ----> AA... (4 Replies)
Hello,
suppose i have a student.dat file whose format is
studentno studentname semester marks1 marks2 marks3 total
then how can i sort first in semester wise and then total wise? I mean semester wise ranking wise record should be displayed. Semester should be displayed in ascending order... (6 Replies)
Hi,
I just stuckup in doing some regular expressions on a file.
I have data which has multiple FHS and BTS segments like:
FHS|12121|LOCAL|2323
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
BTS|0000|MERSTO|LIABLE
FHS|12121|LOCAL|2323
MSH|10101|POTAMAS|2323... (3 Replies)
I have a text file comprising of 3 columns
1. First column - numeric count/frequency of error codes
2. Second column - alphanumeric hyphenated error code
3. Third column - Error code description (alphanumeric)
184 ABCD-954 Errorcodedescription1
35645 DFMS-323 Errorcodedescription2
43534 ... (2 Replies)
Hi,
I am facing a small problem while I am doing the sort.
Problem Definition:
I have a file which has the following data.
>cat test.dat
zxzxc
asdasd
qwaxcZa
qwaxcA
When I do a sort on this file.
the result set is
asdasd
qwaxcA (4 Replies)