Re: scripting text replacement

2008-11-10 Thread Daniel Howard
On Sat, Nov 8, 2008 at 10:43 AM, bsd [EMAIL PROTECTED] wrote:

 I have a file containing a list of items like that:

 line1item1 line1item2 line1item3
 line2item1 line2item2 line2item3
 …400 times

 I need to insert this into another text file using printf() items should be
 converted into variable looping… like that:

 printf Bla bla bla $1 bla bla $2 bla bla $3 bla bla $2

awk '{print Bla bla bla $1 bla bla $2 bla bla $3 bla bla $2}'
 file.txt  file-bla-bla-bla.txt

-d

-- 
http://dannyman.toldme.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: scripting text replacement

2008-11-09 Thread Jonathan McKeown
On Sunday 09 November 2008 00:02:11 Giorgos Keramidas wrote:
 On Sat, 8 Nov 2008 19:43:52 +0100, bsd [EMAIL PROTECTED] wrote:
 
  I have a file containing a list of items like that:
 
  line1item1 line1item2 line1item3
  line2item1 line2item2 line2item3
  …400 times
 
  I need to insert this into another text file using printf() items should
  be converted into variable looping… like that:
 
  printf Bla bla bla $1 bla bla $2 bla bla $3 bla bla $2

 A little more detail about the Bla bla part may be important in our
 effort to help you effectively.  What you seem to describe above may be
 trivial to do with awk(1):

More detail definitely needed. When you say insert into another text file, do 
you mean you want to create an output file in which each line is identical 
bar the four parameters from the first file (in other words your bla bla bla 
is the same for every input line) (in which case a simple awk '{printf}' will 
meet the need), or are you actually doing a merge of two files where bla bla 
bla represents the text from the next line of the other input file and 
changes from line to line?

Jonathan
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: scripting text replacement

2008-11-08 Thread Giorgos Keramidas
On Sat, 8 Nov 2008 19:43:52 +0100, bsd [EMAIL PROTECTED] wrote:
 Sorry for this cross posting, but I can not find a good bash mailing
 list…
 I am certain FreeBSD gurus will provide me with a fast and reliable
 answer to this little question.

 Here is the deal:
 -

 I have a file containing a list of items like that:

 line1item1 line1item2 line1item3
 line2item1 line2item2 line2item3
 …400 times

 I need to insert this into another text file using printf() items should
 be converted into variable looping… like that:

 printf Bla bla bla $1 bla bla $2 bla bla $3 bla bla $2

 The main thing is that I can not get $1 $2 $3 to correspond to
 line1item1 line1item2 line1item3

A little more detail about the Bla bla part may be important in our
effort to help you effectively.  What you seem to describe above may be
trivial to do with awk(1):

,---
| $ cat /tmp/inputfile
| line1item1 line1item2 line1item3
| line2item1 line2item2 line2item3
| $ awk '{
| printf Bla bla bla %s bla bla %s bla bla %s bla bla %s\n,
| $1, $2, $3, $2;
|   }' /tmp/inputfile
| Bla bla bla line1item1 bla bla line1item2 bla bla line1item3 bla bla 
line1item2
| Bla bla bla line2item1 bla bla line2item2 bla bla line2item3 bla bla 
line2item2
| $
`---

or with a short script in sed(1) or Perl:

,---
| $ perl \
|   -pe 's/(\S+)\s+(\S+)\s+(\S+)/Bla bla bla $1 bla bla $2 bla bla $3 bla bla 
$2/' \
|   /tmp/inputfile
| Bla bla bla line1item1 bla bla line1item2 bla bla line1item3 bla bla 
line1item2
| Bla bla bla line2item1 bla bla line2item2 bla bla line2item3 bla bla 
line2item2
| $
`---

More complex substitutions can be scripted in almost any scripting
language you prefer.

HTH,
Giorgos

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]