linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* split a file or return shell variable to a program
@ 2004-04-22 18:33 vick Julius
  2004-04-22 19:04 ` Glynn Clements
  2004-04-22 21:16 ` rich+ml
  0 siblings, 2 replies; 6+ messages in thread
From: vick Julius @ 2004-04-22 18:33 UTC (permalink / raw)
  To: linux-admin


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: split a file or return shell variable to a program
  2004-04-22 18:33 split a file or return shell variable to a program vick Julius
@ 2004-04-22 19:04 ` Glynn Clements
  2004-04-23  8:10   ` urgrue
  2004-04-22 21:16 ` rich+ml
  1 sibling, 1 reply; 6+ messages in thread
From: Glynn Clements @ 2004-04-22 19:04 UTC (permalink / raw)
  To: vick Julius; +Cc: linux-admin


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 <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: split a file or return shell variable to a program
  2004-04-22 18:33 split a file or return shell variable to a program vick Julius
  2004-04-22 19:04 ` Glynn Clements
@ 2004-04-22 21:16 ` rich+ml
  2004-07-14 21:55   ` running fsck in runlevel 3 and single user mode serial access problems A. R. Vener
  1 sibling, 1 reply; 6+ messages in thread
From: rich+ml @ 2004-04-22 21:16 UTC (permalink / raw)
  To: vick Julius; +Cc: linux-admin

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 <julius_vick@hotmail.com>
> 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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: split a file or return shell variable to a program
  2004-04-22 19:04 ` Glynn Clements
@ 2004-04-23  8:10   ` urgrue
  0 siblings, 0 replies; 6+ messages in thread
From: urgrue @ 2004-04-23  8:10 UTC (permalink / raw)
  To: linux-admin

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 <glynn.clements@virgin.net>
> -
> 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
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* running fsck in runlevel 3 and  single user mode serial access problems
  2004-04-22 21:16 ` rich+ml
@ 2004-07-14 21:55   ` A. R. Vener
  2004-07-14 23:19     ` Lothar Braun
  0 siblings, 1 reply; 6+ messages in thread
From: A. R. Vener @ 2004-07-14 21:55 UTC (permalink / raw)
  To: linux-admin

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: running fsck in runlevel 3 and  single user mode serial access problems
  2004-07-14 21:55   ` running fsck in runlevel 3 and single user mode serial access problems A. R. Vener
@ 2004-07-14 23:19     ` Lothar Braun
  0 siblings, 0 replies; 6+ messages in thread
From: Lothar Braun @ 2004-07-14 23:19 UTC (permalink / raw)
  To: linux-admin

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-07-14 23:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-22 18:33 split a file or return shell variable to a program vick Julius
2004-04-22 19:04 ` Glynn Clements
2004-04-23  8:10   ` urgrue
2004-04-22 21:16 ` rich+ml
2004-07-14 21:55   ` running fsck in runlevel 3 and single user mode serial access problems A. R. Vener
2004-07-14 23:19     ` Lothar Braun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).