It is currently Thu, 20 Jan 2022 10:12:17 GMT



 
Author Message
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have a text file and I want to know why, of all its lines, are
longer than N characters... how can I do it with bash? I read
awk and grep manpages, but I couldn't understand (maybe because
of my poor english ^__^') which are the option(s) to use, and
if the right command is one of those...

...hints?

- --
Dario Basile
- ----------------------------------------------------------------
Ex humo, homo; ex fico, fica; ex fica, ficcare.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAXowg7mRkrRsDl/8RAjivAKDy3VLxRLQof9kDJQMSAugpNan2EACg4yBH
UPJvd+PngFUu1MGb2zOdsy0=
=6cZ9
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 14:47:51 GMT   
 Lines longer than...

    What do you want to do with the file?

    You can use grep to search for lines containing a string or
    regular expression; you can read the file line by line; you can
    select only certain columns from the file; etc., etc........

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License



 Fri, 08 Sep 2006 15:29:17 GMT   
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In <c3m4kc$290db...@ID-210011.news.uni-berlin.de> Chris F.A.

I have a *very* long shell script, and I need to print it.

Some lines are longer than others, and that messes up my print.
I can't just load the file in a Word Processor and have it word
wrap the lines for me, because it would not insert the escape
(\) code before new lines, thus making the file unusable as a
script and also more difficult to read.

So what I am trying to do is finding the longer lines and
word-wrapping them the right way, but because the file is so
long (more than 30000 lines, including comments) I am looking
for an alternative to manually scroll it seeking longer lines
(which would destroy my eyes...).

- --
Dario Basile
- ----------------------------------------------------------------
Sinite cunnulos ad me venire.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAXqCC7mRkrRsDl/8RAuc7AJwJFqUYqvqVjPITC68fH/CecWNI3QCdFQSB
Vhmfo07jdYzA1A7a2fMDjvo=
=SerL
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 16:14:50 GMT   
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Not sure what you exactly want to do? However following 'man awk'
on my box (GNU Awk 3.1.3):

length([s])             Returns  the  length  of  the string s, or
                        the length of $0 if s is not supplied.

Something like this should do the trick:

 awk 'length>50' infile

If you need more help, please be more specific, what you actually
want to do.

- --
Michael Heiming (GPG-Key ID: 0xEDD27B94)

Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAXqGrAkPEju3Se5QRAvaSAKCQqOL+oPjso8jPjflyeR4qLeFHIACdFJ50
R0OvbairsAPxwmiKYEfSOoo=
=PEtM
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 16:19:56 GMT   
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[..]

Ah, if this is all you want to do, try:

man fmt

Good luck

- --
Michael Heiming (GPG-Key ID: 0xEDD27B94)

Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAXqI/AkPEju3Se5QRAuO4AKCqzQk5iEL7Af+ZB+eXfdErlIcF8wCfYLGG
RF7JjAYUfJyA0hwOoXCorQI=
=jErz
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 16:22:25 GMT   
 Lines longer than...
   Dario Basile <bu++3rO_P0...@+in.1t>:

awk -v N=80 '{if ((L=length($0)) > N)
              {print "Line number " NR " has " L " chars"} }' file.txt

Stefan

.



 Fri, 08 Sep 2006 16:25:20 GMT   
 Lines longer than...

to get lines longer than 'N' characters in a file, we can do this:

grep -v '^.{1,N}$' yourfile

or,

sed -e '
   /./!d
   /^.\{1,N\}$/d
' yourfile

or,

awk 'length+0>N' yourfile



 Fri, 08 Sep 2006 18:04:51 GMT   
 Lines longer than...

man fold

        Ed.



 Fri, 08 Sep 2006 21:44:16 GMT   
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In <IMydna9o0rsscMPdRVn...@comcast.com> Ed Morton wrote:

Fold has nothing to do with my request, BTW thanks for the
reply. Next time, please, try to read my whole message instead
of just the first line, before posting an answer.

- --
Dario Basile
- ----------------------------------------------------------------
Si culus erat in principio, nunc goliarde pete ad cunnum.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAXvBl7mRkrRsDl/8RAl1iAJsGixPbXWIMDYH9rfHrp8wBiHu1owCgzJL4
avL3IrYkcuELEm4NjsNlyJk=
=JUwt
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 21:55:44 GMT   
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In <1o7m3c.v6l...@news.heiming.de> Michael Heiming wrote:

fmt, just as fold, would reformat my script, just like a word
processor would do. I need to automatically find the long lines
to *manually* reformat them, so I can just insert a new line
(hit return) or add an escape character, based on what kind of
line (comment or script, respectively) I am editing.

BTW thanks for the answer.

- --
Dario Basile
- ----------------------------------------------------------------
Pisellus abundat in ano stultorum.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAXvE77mRkrRsDl/8RAqL3AJ9ojpEEk8J1gmTx4bisQ+fBdjrP2QCg7Kl0
dZVpRk9I6lhpUtTT10d3RiA=
=s0zC
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 21:59:14 GMT   
 Lines longer than...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In <c3m80q$esd$0...@news.t-online.com> Stefan Lagotzki wrote:

Thanks, that worked! :-)

- --
Dario Basile
- ----------------------------------------------------------------
Asinus asinum fricat, fessus fessam non fricat.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAXvJ77mRkrRsDl/8RAvJYAKDrLUzfdrSg1gPRmn77WQ1j/RzBcQCeKeJN
clVh8x/3s3Om6UhmDDs+QDM=
=UP7S
-----END PGP SIGNATURE-----



 Fri, 08 Sep 2006 22:04:35 GMT   
 Lines longer than...
In article <AfC7c.85851$z23.3676...@news3.tin.it>,
Dario Basile  <BUTT3rO_P0...@+1N.i+> wrote:
...

The advice you get in this newsgroup is generally (though not always) worth
what you pay for it.

Anyway, if all you want to do is print, then it is unclear to me why you
need backslash continuation characters on the wrapped lines, although
I suppose it *might* make it a little prettier to see it explicitly.  It
seems to me that your request makes more sense if what you want is to
convert it to a printer-friendly format that can also be executed.

In that case, you might like to try something like:

#!gawk
# Not complete - getting it to actually work (*) left as an exercise...
# (*) Wrapping at word boundaries.
{
while (length($0) > 75) {
    print substr($0,1,75),"\\"
    $0 = substr($0,75)
    }
print



 Fri, 08 Sep 2006 22:05:36 GMT   
 Lines longer than...

You're wrong. It may or may not have anything to do with what you wanted
to say, but it is applicable to what you actually requested.

BTW thanks for the

You're welcome.

Next time, please, try to read my whole message instead

I did, as did the others who apparently misunderstood what you actually
wanted. Next time I'll just ignore you're questions and hopefully others
in this NG will follow suit having seen you're response when you don't
like or understand the answers you get.

        Ed.



 Fri, 08 Sep 2006 23:58:25 GMT   
 Lines longer than...
In article <405F0D21.30...@lsupcaemnt.com>,
Ed Morton  <mor...@lsupcaemnt.com> wrote:
...

Nope, Ed.  You're wrong.  The original post clearly indicates that
backslashes are involved.  That's what makes this thread (moderately)
interesting (as, otherwise, it would be trivial to solve with fold, etc).



 Sat, 09 Sep 2006 01:04:50 GMT   
 Lines longer than...
In article <ed24e4cf.0403220204.1f3e7...@posting.google.com>, rakesh

There are a few problems with this. It's an extended regexp, so
you need -E, and it will select empty lines. I'd suggest this :

  grep -E '.{81,}' yourfile

It's also faster, at least with GNU grep :

  $ perl -e '
    foreach $i (0..99) {
      foreach $j (0..81) {
        print "x" x $j, "\n";
      }
    }' >/tmp/data
  $ time grep -Ev '^.{1,80}$' /tmp/data >/dev/null
  real    0m0.045s
  user    0m0.040s
  sys     0m0.000s
  $ time grep -E '.{81,}' /tmp/data >/dev/null
  real    0m0.010s
  user    0m0.010s
  sys     0m0.010s

--
Andr Majorel <URL: http://www.**-**.com/ ~amajorel/>
Depuis Malraux, on n'a malheureu{*filter*}t jamais su trouver de
liens entre le monde intellectuel et la droite.
-- Jacques Chirac, cit dans le Canard Encha?n du 2004-02-25



 Sat, 09 Sep 2006 02:24:25 GMT   
 
   [ 20 post ]  Go to page: [1] [2]

Similar Threads

1. On-line/Off-line long-term power backup

2. q: looking for random text generator single line long

3. Real Time UNIX Responses (131 lines long)

4. slrn - how to make it allow lines longer then 80 characters?

5. how to truncate (or wrap) lines longer than 80 chars???

6. Need to edit a file with a line longer than 2048 chars!

7. security problem of /etc/exports line longer than 256 charactors for AIX?

8. Command line: How long is too long?

9. Line splitting long lines


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software