Bash script find longest line/lines in several files
Hello everyone...
I need to find out, how to find longest line or possibly lines in several files which are arguments for script. The thing is, that I tried some possibilities before, but nothing worked correctly.
Example
when i use:
it will only print 1 longest line. But what if there are 2 or more lines with exact length? Or there are similar lines in different files?
this is my second through, but same problem as above and i don't know how to make it.
Thanks for any solutions
Last edited by Neo; 10-25-2010 at 06:10 AM..
Reason: code taggies, typos
Dear All,
To find the length of the longest line from a file i have used wc -L which is giving the proper output...
But the problem is AIX os does not support wc -L command.
so is there any other way 2 to find out the length of the longest line using awk or sed ?
Regards,
Pankaj (1 Reply)
Hi Everyone,
I am trying to write a shell script that can find the longest phrase that appears at least twice in an online news article. The HTML has been parsed through an HTML parser, converted to XML and the article content extracted. I have put this article content in a text file to work... (24 Replies)
Good Morning/Afternoon All,
I am using the nawk utility in korn shell to find the longest field and display that result.
My Data is as follows:
The cat ran
The elephant ran
Milly ran too
We all ran
I have tried nawk '{ if (length($1) > len) len=length($1); print $1}' filename
The... (5 Replies)
Hello all,
I need to find the longest string in a select field and print that field.
I have tried a few different methods and I always end up one step from where I need to be.
Methods thus far:
nawk '{if (length($1) > long) long=length($1); if(length($1)==long) print $1}'
The above... (6 Replies)
I am writing a bash script to find out all the files in a directory which are empty. I am running into multiple issues. I will really appreciate if someone can please help me.
#!/bin/bash
DATE=$(date +%m%d%y)
TIME=$(date +%H%M)
DIR="/home/statsetl/input/civil/test"
... (1 Reply)
Running below line gives 3957 as length of longest line in file 20121119_SRMNotes_init.dat
awk ' { if ( length > 3950 ) { x = length } }END{ print x }' 20121119_SRMNotes_init.dat
While wc -L 20121119_SRMNotes_init.dat gives output as 4329. Why is there a difference between these two commands.... (2 Replies)
I want to find common line in two files and replace the next line of first file with the next line of second file. (sed,awk,perl,bash any solution is welcomed ) Case Ignored. Multiple Occurrence of same line.
File 1:
hgacdavd
sndm,ACNMSDC
msgid "Rome"
msgstr ""
kgcksdcgfkdsb... (4 Replies)
Hi ,
i have a file with data as below.This is same file. But actual file contains to many rows.
i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ?
Field 004... (7 Replies)
I am trying to make my script as simple as a possible but, I am not sure if the way I am approaching is necessarily the most efficient or effective it can be. What I am mainly trying to fix is a for loop to remove a string from the specified files and within this loop I am trying to copy the lines... (2 Replies)
Hello,
I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies
LEARN ABOUT NETBSD
rcorder
RCORDER(8) BSD System Manager's Manual RCORDER(8)NAME
rcorder -- print a dependency ordering of interdependent files
SYNOPSIS
rcorder [-k keep] [-s skip] file ...
DESCRIPTION
rcorder is designed to print out a dependency ordering of a set of interdependent files. Typically it is used to find an execution sequence
for a set of shell scripts in which certain files must be executed before others.
Each file passed to rcorder should be annotated with special lines (which look like comments to the shell) which indicate the dependencies
the files have upon certain points in the sequence, known as ``conditions'', and which indicate, for each file, which ``conditions'' may be
expected to be filled by that file.
Within each file, a block containing a series of ``REQUIRE'', ``PROVIDE'', ``BEFORE'' and ``KEYWORD'' lines should appear. The format of the
lines is rigid. Each line must begin with a single ``#'', followed by a single space, followed by ``PROVIDE:'', ``REQUIRE:'', ``BEFORE:'',
or ``KEYWORD:''. No deviation is permitted. Each dependency line is then followed by a series of conditions, separated by whitespace. Mul-
tiple ``PROVIDE'', ``REQUIRE'', ``BEFORE'' and ``KEYWORD'' lines may appear, but all such lines must appear in a sequence without any inter-
vening lines, as once a line that does not follow the format is reached, parsing stops.
The options are as follows:
-k Add the specified keyword to the ``keep list''. If any -k option is given, only those files containing the matching keyword are
listed.
-s Add the specified keyword to the ``skip list''. If any -s option is given, files containing the matching keyword are not listed.
An example block follows:
# REQUIRE: networking syslog
# REQUIRE: usr
# PROVIDE: dns nscd
This block states that the file in which it appears depends upon the ``networking'', ``syslog'', and ``usr'' conditions, and provides the
``dns'' and ``nscd'' conditions.
A file may contain zero ``PROVIDE'' lines, in which case it provides no conditions, and may contain zero ``REQUIRE'' lines, in which case it
has no dependencies. A file containing no ``PROVIDE'', ``REQUIRE'', or ``BEFORE'' lines may be output at an arbitrary position in the depen-
dency ordering.
There must be at least one file with no dependencies in the set of arguments passed to rcorder in order for it to find a starting place in
the dependency ordering.
DIAGNOSTICS
rcorder may print one of the following error messages and exit with a non-zero status if it encounters an error while processing the file
list.
Requirement %s has no providers, aborting. No file has a ``PROVIDE'' line corresponding to a condition present in a ``REQUIRE'' line in
another file.
Circular dependency on provision %s, aborting. A set of files has a circular dependency which was detected while processing the stated con-
dition.
Circular dependency on file %s, aborting. A set of files has a circular dependency which was detected while processing the stated file.
SEE ALSO rc(8)HISTORY
The rcorder program first appeared in NetBSD 1.5.
AUTHORS
Written by Perry E. Metzger <perry@piermont.com> and Matthew R. Green <mrg@eterna.com.au>.
BSD April 23, 2003 BSD