09-29-2004
I don't see any input being redirected into it from a pipe or shell. So it will read from stdin. If that's a file, it should be alright. If not it will read from the tty.
But this has nothing to do with :
run6[101]: syntax error at line 121 : `(' unexpected
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
I found a command who prints x lines before and after a line who contain a searched string in a text file.
The command is :
-------------------
nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=2 a=4 s="string" file1
...where "b" and "a" are the number of lines to print... (2 Replies)
Discussion started by: ctap
2 Replies
2. Shell Programming and Scripting
i'm new to shell scripting and have a problem please help me
in the script i have a nawk block which has a variable count
nawk{
.
.
.
count=count+1
print count
}
now i want to access the value of the count variable outside the awk block,like..
s=`expr count / m`
(m is... (5 Replies)
Discussion started by: saniya
5 Replies
3. Shell Programming and Scripting
What am I doing wrong here? I get syntax error.
I am trying to parse a file looking for the lines with "running" as the first field then print the 5th field, then looking at the 9th field for specific values and writing the whole line to a junk file.
nawk ';
{if ($1 == "running")... (10 Replies)
Discussion started by: beppler
10 Replies
4. Shell Programming and Scripting
Hi Gurus,
I am using a script as under :
read string
nawk -v search="$string" '
/a/,/z/ {
block = (block ? block ORS : "") $0;
}
/z/ {
if (block ~ search)
print block;
} ' <File>
nawk -v search="$string" '
/b/,/z/ {
... (1 Reply)
Discussion started by: vanand420
1 Replies
5. Shell Programming and Scripting
hi people;
this is my two awk code:
nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt
nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies
6. UNIX for Dummies Questions & Answers
Hi,
Please help me I want to filter all messages having a value less than a particular value..Please advice how to use <= in the below red marked script..
Getting the error as no such file or directory for the marked line no.
Thanks in advance...
Script is as under :
read message
gawk... (5 Replies)
Discussion started by: vanand420
5 Replies
7. Shell Programming and Scripting
help out with code. two files aaa bbb contains some records..output file xyz should be like this..see below
i/p file:aaa
08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878
i/p file: bbb
60521|60510
o/p file :xyz
60510|08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878 (5 Replies)
Discussion started by: Diddy
5 Replies
8. Shell Programming and Scripting
hi guys,
I am writing a code and have stuck at one point. Inside nawk I am storing my desired variable a, I just need to find if a is present in an external file error.log or not. If yes, print something. grep or for loop not working properly inside nawk. Sample code provided.
nawk '
BEGIN... (5 Replies)
Discussion started by: shekhar2010us
5 Replies
9. Shell Programming and Scripting
I don't know whats wrong with the code here.
Its giving double counts.
nawk -F# '
{
if( match($2, "= ") > 0)
num=substr($2,RSTART+2,length($2)-1);
if (match($20, "= ") > 0)
res=substr($20,RSTART+2,length($20)-1);
if(match(num,... (2 Replies)
Discussion started by: jagpreetc
2 Replies
10. Shell Programming and Scripting
Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare
nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies
LEARN ABOUT CENTOS
ipc::open2
IPC::Open2(3pm) Perl Programmers Reference Guide IPC::Open2(3pm)
NAME
IPC::Open2 - open a process for both reading and writing using open2()
SYNOPSIS
use IPC::Open2;
$pid = open2(*CHLD_OUT, *CHLD_IN, 'some cmd and args');
# or without using the shell
$pid = open2(*CHLD_OUT, *CHLD_IN, 'some', 'cmd', 'and', 'args');
# or with handle autovivification
my($chld_out, $chld_in);
$pid = open2($chld_out, $chld_in, 'some cmd and args');
# or without using the shell
$pid = open2($chld_out, $chld_in, 'some', 'cmd', 'and', 'args');
waitpid( $pid, 0 );
my $child_exit_status = $? >> 8;
DESCRIPTION
The open2() function runs the given $cmd and connects $chld_out for reading and $chld_in for writing. It's what you think should work when
you try
$pid = open(HANDLE, "|cmd args|");
The write filehandle will have autoflush turned on.
If $chld_out is a string (that is, a bareword filehandle rather than a glob or a reference) and it begins with ">&", then the child will
send output directly to that file handle. If $chld_in is a string that begins with "<&", then $chld_in will be closed in the parent, and
the child will read from it directly. In both cases, there will be a dup(2) instead of a pipe(2) made.
If either reader or writer is the null string, this will be replaced by an autogenerated filehandle. If so, you must pass a valid lvalue
in the parameter slot so it can be overwritten in the caller, or an exception will be raised.
open2() returns the process ID of the child process. It doesn't return on failure: it just raises an exception matching "/^open2:/".
However, "exec" failures in the child are not detected. You'll have to trap SIGPIPE yourself.
open2() does not wait for and reap the child process after it exits. Except for short programs where it's acceptable to let the operating
system take care of this, you need to do this yourself. This is normally as simple as calling "waitpid $pid, 0" when you're done with the
process. Failing to do this can result in an accumulation of defunct or "zombie" processes. See "waitpid" in perlfunc for more
information.
This whole affair is quite dangerous, as you may block forever. It assumes it's going to talk to something like bc, both writing to it and
reading from it. This is presumably safe because you "know" that commands like bc will read a line at a time and output a line at a time.
Programs like sort that read their entire input stream first, however, are quite apt to cause deadlock.
The big problem with this approach is that if you don't have control over source code being run in the child process, you can't control
what it does with pipe buffering. Thus you can't just open a pipe to "cat -v" and continually read and write a line from it.
The IO::Pty and Expect modules from CPAN can help with this, as they provide a real tty (well, a pseudo-tty, actually), which gets you back
to line buffering in the invoked command again.
WARNING
The order of arguments differs from that of open3().
SEE ALSO
See IPC::Open3 for an alternative that handles STDERR as well. This function is really just a wrapper around open3().
perl v5.16.3 2013-03-04 IPC::Open2(3pm)