I am seeing a weird behavior during the execution of the shell program.
The shell programs loops through a file which has a list of files. for each file the programs cats the file, pipes the output to sed command and then on to an awk program. But while execution, the order of execution(cat,sed and awk) is reversed(to cat, awk and sed) for one file and for the next file the order seems to be correct. This behavior alternates until the end of loop.
I have resolved this issue by rewriting in awk, but just curious to know if someone had come across this weird behavior or have any clue of what's going on.
Last edited by methyl; 01-12-2012 at 11:51 AM..
Reason: please use code tags.
Please use code tags when posting code or sample i/o-put.
There are several things worth noting on your script:
1. Shell loops through file lines are very ineffective. You are using filters, which are operating on one line at a time, and are optimized for this kind of processing. No need for the shell loop.
2. sed command can be gotten rid of, if the FS of awk is specified in a more general way, e.g. -F'\\^ *' would eat up the spaces after the delimiter, or even more general -F' *\\^ *', which would handle situation with spaces before or/and after the ^.
3. The strangest thing there though, is that you redirect the output into the same file, for each line, and you are using the > operator, which will truncate it to zero length. So actually you will not get anything but the last line processed.
4. Useless use of cat
Can you post sample of the content of $FILE, so that I can run it and see the behavior?
From my reading your original script, I am convinced that after running that code, I would find only one line in the _rename.txt output file, assuming the $FILE contains at least one .pdf.
I don't believe that there is any "weird behavior" there, it's just doing something else than the person who wrote it intended, which is pretty much a universal law in the field of programming. The computer programs don't do what we want, but what we write.
If you create a pipe
How could possibly program2 execute before program1? It would have to be a major bug in the shell.
To be able to determine why you believed that the order reversed, I would need to see a sample input.
Hi all,
Here is a portion of my script test.sh:
#!/bin/bash
tar -cf $name.tar $name && pbzip2 $name.tar
2-Sending .tar.bz2 to destination node
Please, i have a question. The execution of the second instruction is done, but i do not see the result of pbzip2
I have to send this... (2 Replies)
Hi,
I have two scripts which are mentioned in execute.sh
more execute.sh
./script1.sh //line 1 should not return error
./script2.sh //line 2 may return error
./script2.sh //line 3 should not return error
Condition: I want script1.sh to complete before starting script2.sh... (1 Reply)
Hi guys,
I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file
for eg:
file 1:
xx|yy|"xyz|zzz"|zzz|12...
using below awk command
awk 'BEGIN {FS=OFS="|" } print $3
i would get xyz
But i want as :
xyz|zzz to consider as whole column... (13 Replies)
I got some problem at startup before login such screen splashing, startup blocking on "checking battery status" and screen going black.
Now, that I've solved the above problems I see the desktop screen is upside-down n reversed as well. I tried re-installing nvidia-current, re-installing... (1 Reply)
55,0 5,6 * * * myScript
This cron task will execute on 5:00AM, 5:55AM, 6:00AM and 6:55AM.
Is there any possibility to make it run only in the order specified
such as 5:55AM and 6:00AM (basically only on the 2 intervals) ? (1 Reply)
Dear All
I am trying to write a script to set the SGE job execution order. I named each job with 'job1', 'job2' and 'job3'. I want my script to do: When 'job1' execution is complete, 'job2' is executed; when both 'job1' and 'job2' are complete, 'job3' is executed.
First, I tried this... (0 Replies)
I have an expect script that interrogates several hundred unix servers for both access and directories therein using "ssh user@host ls -l /path". The combination of host/path are unique but the host may be interrogated multiple times if there are multiple paths to test.
The expect script is run... (2 Replies)
Hi all:
I have a problem with a C++ service runing on solaris 10. This service only set a signal on oracle table. When the service detect a cut off on the line (tcp/ip), trigger a cobol program for set the signal OFF. When the line is on again, the service trigger the same cobol program for set... (0 Replies)