split a file or return shell variable to a program
split a file or return shell variable to a program
am 22.04.2004 20:33:45 von vick Julius
Hello everbody
I have a text file I want to split. The file contains some sentences.
between sentences I have empty 1 line. I want to split this file and put
each sentence in a separate file with names 1, 2,3 ...
do you have any idea to split it such as with awk or split?
Here is my strategy:
I wrote a C program in which I call bash shell script to increment a
variable...
In the shell I defined the variable k such as:
$export k=1
in my bash script file,myFile, for testing, I put
echo $k
let k+=1
(or this expression k=`expr $k + 1`)
echo $k
when I run this script file, it gives me
1
2
the problem is when I called form a C or C++ program, such
system("echo $k");
//this gives 1
system("./myFile");
// this display
// 1
//2
system("echo $k");
//here the problem, it display 1 not 2
I want to have the incremented value for k, i.e 2 not the original one.
Do you have any hint?
Vick
____________________________________________________________ _____
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: split a file or return shell variable to a program
am 22.04.2004 21:04:20 von Glynn Clements
vick Julius wrote:
> I have a text file I want to split. The file contains some sentences.
> between sentences I have empty 1 line. I want to split this file and put
> each sentence in a separate file with names 1, 2,3 ...
> do you have any idea to split it such as with awk or split?
You can't do it with split; that only handles the case where each
contains a fixed number of bytes or lines.
You can do it with awk easily enough, e.g.:
#!/usr/bin/awk -f
BEGIN {
ofile = 0;
}
/^ *$/ {
close(ofile);
ofile++;
}
/[^ ]/ {
print > ofile;
}
> Here is my strategy:
>
> I wrote a C program in which I call bash shell script to increment a
> variable...
>
> In the shell I defined the variable k such as:
> $export k=1
> in my bash script file,myFile, for testing, I put
> echo $k
> let k+=1
> (or this expression k=`expr $k + 1`)
> echo $k
>
> when I run this script file, it gives me
> 1
> 2
>
> the problem is when I called form a C or C++ program, such
> system("echo $k");
> //this gives 1
> system("./myFile");
> // this display
> // 1
> //2
> system("echo $k");
> //here the problem, it display 1 not 2
>
> I want to have the incremented value for k, i.e 2 not the original one.
Each process has its own set of environment variables. A process can
modify its own environment variables, but not those of another
process.
If you want to share state between processes, use a file.
--
Glynn Clements
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: split a file or return shell variable to a program
am 22.04.2004 23:16:06 von rich+ml
man setenv.
But anyway you could just:
perl -ne '/\S/ and $x++, `echo "$_">>out.$x`' < your_file
On Thu, 22 Apr 2004, vick Julius wrote:
> Date: Thu, 22 Apr 2004 18:33:45 +0000
> From: vick Julius
> To: linux-admin@vger.kernel.org
> Subject: split a file or return shell variable to a program
>
>
> Hello everbody
> I have a text file I want to split. The file contains some sentences.
> between sentences I have empty 1 line. I want to split this file and put
> each sentence in a separate file with names 1, 2,3 ...
> do you have any idea to split it such as with awk or split?
>
> Here is my strategy:
>
> I wrote a C program in which I call bash shell script to increment a
> variable...
>
> In the shell I defined the variable k such as:
> $export k=1
> in my bash script file,myFile, for testing, I put
> echo $k
> let k+=1
> (or this expression k=`expr $k + 1`)
> echo $k
>
> when I run this script file, it gives me
> 1
> 2
>
> the problem is when I called form a C or C++ program, such
> system("echo $k");
> //this gives 1
> system("./myFile");
> // this display
> // 1
> //2
> system("echo $k");
> //here the problem, it display 1 not 2
>
> I want to have the incremented value for k, i.e 2 not the original one.
>
> Do you have any hint?
>
> Vick
>
> ____________________________________________________________ _____
> Add photos to your messages with MSN 8. Get 2 months FREE*.
> http://join.msn.com/?page=features/featuredemail
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: split a file or return shell variable to a program
am 23.04.2004 10:10:44 von urgrue
here's another way to do it (just with bash):
counter=1
while read line
do
if [ -z $line ] ; then continue
else
echo $line > $counter
counter=`expr $counter + 1`
fi
done < your_sentences_file
On 2004.04.22 22:03, Glynn Clements wrote:
>
> vick Julius wrote:
>
> > I have a text file I want to split. The file contains some
> sentences.
> > between sentences I have empty 1 line. I want to split this file and
> put
> > each sentence in a separate file with names 1, 2,3 ...
> > do you have any idea to split it such as with awk or split?
>
> You can't do it with split; that only handles the case where each
> contains a fixed number of bytes or lines.
>
> You can do it with awk easily enough, e.g.:
>
> #!/usr/bin/awk -f
> BEGIN {
> ofile = 0;
> }
>
> /^ *$/ {
> close(ofile);
> ofile++;
> }
>
> /[^ ]/ {
> print > ofile;
> }
>
> > Here is my strategy:
> >
> > I wrote a C program in which I call bash shell script to increment a
>
> > variable...
> >
> > In the shell I defined the variable k such as:
> > $export k=1
> > in my bash script file,myFile, for testing, I put
> > echo $k
> > let k+=1
> > (or this expression k=`expr $k + 1`)
> > echo $k
> >
> > when I run this script file, it gives me
> > 1
> > 2
> >
> > the problem is when I called form a C or C++ program, such
> > system("echo $k");
> > //this gives 1
> > system("./myFile");
> > // this display
> > // 1
> > //2
> > system("echo $k");
> > //here the problem, it display 1 not 2
> >
> > I want to have the incremented value for k, i.e 2 not the original
> one.
>
> Each process has its own set of environment variables. A process can
> modify its own environment variables, but not those of another
> process.
>
> If you want to share state between processes, use a file.
>
> --
> Glynn Clements
> -
> To unsubscribe from this list: send the line "unsubscribe linux-
> admin"
> in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
running fsck in runlevel 3 and single user mode serial access problems
am 14.07.2004 23:55:19 von salt
Is there a safe way to run fsck in run level 3?
I have a situation where if I shutdown this system it will not boot until
I run fsck to clean up the disk. Also, it is a headless Linux system
and if I try to access the system in single user mode over the
serial port, I keep getting a new maintenance prompt after
every keystroke. So I cannot get into single user mode from the seiral port
and I cannot complete my boot
until I run fsck from single user mode. Bummer.
I was able to attach a monitor and keyboard and enter single user mode
from the console. Then I can run fsck and finish my boot. But i
do not want to keep physically attaching a keyboard and monitor to this machine
and trottting over to it every time it needs a reboot.
Any thoughts on how to handle this?
Thanks,
Rudy
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: running fsck in runlevel 3 and single user mode serial access problems
am 15.07.2004 01:19:27 von Lothar Braun
On Wednesday 14 July 2004 11:55 pm, you wrote:
> Is there a safe way to run fsck in run level 3?
The only important thing is, that the partition on which you want to run is
mounted read-only.
So you can try to remount it:
mount -o remount,ro /mountpoint
Finished fsck you can mount it writable with
mount -o remount,rw /mountpoint
Hope this helps
Lothar
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html