Using xargs perl to join lines

C

charissaf

Hello,
FreeBSD 4.10
#!/bin/ksh

I'm looking for some guidance on how to use a combination of grep and
xargs to find lines in multpile files beginning with > and append them
to the previous line.

For example, ideally I would like to use:

grep -r -l '^>' . | xargs perl -pi -e :a -e '$!N;s/\n>/>/;ta' -e 'P;D'

I am basing this one liner on the following sed example:

# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
# sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'

The error I receive is: N: Event not found.

A sample file would have a line similar to
<htm
The ideal result is to bring the closing > up to the preceeding line:
<htm>

Please look at my syntax or let me know if there is another way of
doing this operation using xargs perl.

Thank you!
C
 
C

charissaf

Hello,
FreeBSD 4.10
#!/bin/ksh

I'm looking for some guidance on how to use a combination of grep and
xargs to find lines in multpile files beginning with > and append them
to the previous line.

For example, ideally I would like to use:

grep -r -l '^>' . | xargs perl -pi -e :a -e '$!N;s/\n>/>/;ta' -e 'P;D'

I am basing this one liner on the following sed example:

# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
# sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'

The error I receive is: N: Event not found.

A sample file would have a line similar to
<htm



The ideal result is to bring the closing > up to the preceeding line:
<htm>

Please look at my syntax or let me know if there is another way of
doing this operation using xargs perl.

Thank you!
C

More info:
sample file has
<htm
Also, I turned on the perl -w option and have the following info:
Bareword found where operator expected at -e line 2, near "$!N"
(Missing operator before N?)
Can't call method "a" without a package or object reference at -e line
1, <> chunk 1.
 
J

John W. Krahn

Hello,
FreeBSD 4.10
#!/bin/ksh

I'm looking for some guidance on how to use a combination of grep and
xargs to find lines in multpile files beginning with > and append them
to the previous line.

For example, ideally I would like to use:

grep -r -l '^>' . | xargs perl -pi -e :a -e '$!N;s/\n>/>/;ta' -e 'P;D'

I am basing this one liner on the following sed example:

# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
# sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'

The error I receive is: N: Event not found.

Of course Perl cannot run sed code just as sed cannot run Python code.

A sample file would have a line similar to
<htm

The ideal result is to bring the closing > up to the preceeding line:
<htm>

Please look at my syntax or let me know if there is another way of
doing this operation using xargs perl.

$ echo "
<html

" | perl -076pe's/\s+>$/>/'

<html>




John
 
C

charissaf

Of course Perl cannot runsedcode just assedcannot run Python code.




$ echo "
<html

" | perl -076pe's/\s+>$/>/'

<html>

John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall- Hide quoted text -

- Show quoted text -

Wow, thank you for your help!
 
C

Clenna Lumina

Joe said:
Are you aware that some shells require ! to be quoted as \! even
inside ''? -Joe

My bash shell doesn't treat ! as special when in single quotes.
Otherwise, it acts as a histoy shortcut:

$ echo 12345
12345
$ echo 123
123
$ echo ABC
ABC
$ history | tail -n 4 | head -n 3
25767 echo 12345
25768 echo 123
25769 echo ABC
$ perl -e 'print "[", shift, "]\n";' "!25767"
perl -e 'print "[", shift, "]\n";' "echo 12345"
[echo 12345]
$ perl -e 'print "[", shift, "]\n";' !25767
perl -e 'print "[", shift, "]\n";' echo 12345
[echo]
$ perl -e 'print "[", shift, "]\n";' '!25767'
[!25767]
$ perl -e 'print "[", shift, "]\n";' \!25767
[!25767]
$ echo $SHELL
/bin/bash
$ bash --version
GNU bash, version 2.05a.0(1)-release (i686-pc-linux-gnu) ...


Howver, I checked with tcsh, and it doesn't seem to care if it's single
quoted or not (kinda odd?)

$ echo 123
123
$ echo 456
456
$ echo 789
789
$ history | tail -n 4 | head -n 3
2 9:27 echo 123
3 9:27 echo 456
4 9:27 echo 789
$ perl -e 'print "[", shift, "]\n";' "!3"
perl -e 'print "[", shift, "]\n";' "echo 456"
[echo 456]
$ perl -e 'print "[", shift, "]\n";' '!3'
perl -e 'print "[", shift, "]\n";' 'echo 456'
[echo 456]
$ perl -e 'print "[", shift, "]\n";' '\!3'
[!3]
$ echo $version
tcsh 6.10.00 (Astron) 2000-11-19 (i386-intel-linux) ...


I thought all shells are not supposed regard single quoted characters as
special?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top