laco42
October 18, 2009, 1:28pm
1
Hi!
Could you pls help me with my problem?
My task is to find the longest line in several files - that's not the problem
the problem is, I want command bellow to be stored in array, but one result per line:
set line = (`cat $file | awk '{print NR, length, $0, "\n"}' | grep "^[0-9]* $longest"`)
the output of command
foreach r ($line)
echo "Output: $r"
end
is:
Output: 2
Output: 2
Output: 22
Output: 3
Output: 2
Output: aa
but it should look like this:
Output: 2 2 22
Output: 3 2 aa
(in other words - I need command set line..... to be an array of lines, not words)
thanks a lot
Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful
My task is to find the longest line in several files - that's not the problem
the problem is, I want command bellow to be stored in array, but one result per line:
set line = (`cat $file | awk '{print NR, length, $0, "\n"}' | grep "^[0-9]* $longest"`)
the output of command
In a real scripting shell, you would set the field separator to a newline:
IFS='
'
line=( $( awk '{print NR, length, $0, "\n"}' "$file" | grep "^[0-9]* $longest" ) )
I don't see an equivalent in csh, but I only gave the man page a quick glance.
danmero
October 18, 2009, 10:19pm
3
You just complicate your life :rolleyes:
awk '{max=(max>NF)?max:NF}END{print max}' *
for any file in current directory
laco42
October 19, 2009, 1:28am
4
I got the following error: Unmatched '. or when I modify it:
IFS='\
'
IFS=
: Command not found.
danmero: well, but I need to print the whole line (not just its length) - and if there are more line with max length, print them all