All of lore.kernel.org
 help / color / mirror / Atom feed
From: urgrue <urgrue@tumsan.fi>
To: linux-admin@vger.kernel.org
Subject: Re: split a file or return shell variable to a program
Date: Fri, 23 Apr 2004 11:10:44 +0300	[thread overview]
Message-ID: <20040423081044.GC23181@fede2.tumsan.fi> (raw)
In-Reply-To: <16520.5940.736287.302160@cerise.nosuchdomain.co.uk>; from glynn.clements@virgin.net on Thu, Apr 22, 2004 at 22:03:58 +0300

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
> 
> 

  reply	other threads:[~2004-04-23  8:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040423081044.GC23181@fede2.tumsan.fi \
    --to=urgrue@tumsan.fi \
    --cc=linux-admin@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.