![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Expect buffer size increase, please help | jaduks | Shell Programming and Scripting | 1 | 10-12-2007 08:07 AM |
| how to increase size of the console screen buffer ? | the_learner | UNIX for Dummies Questions & Answers | 5 | 04-25-2007 02:31 PM |
| How to increase buffer size in Unix | ziabegg | UNIX for Dummies Questions & Answers | 3 | 01-05-2007 11:17 AM |
| How to increase the buffer size in Unix | ziabegg | UNIX for Advanced & Expert Users | 0 | 12-22-2006 11:11 PM |
| buffer cache size | gsr_kashyap | Linux | 0 | 09-06-2006 10:34 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Increase the buffer size to read lengthy lines
Hi All,
I am trying to read output from a command. The output format is as follows: Code:
Thursday 13 Mar 2008 Information This is sample text Friday 14 Mar 2008 Warning This is one more sample text The problem is sometimes the 2nd line's length is more and that is being read as two lines in Unix. But i want to read that as one line itself. Can we increase the line buffer size in Unix? I hope the question is clear. Regards, Ssunda. |
| Forum Sponsor | ||
|
|
|
|||
|
Your problem is not "buffer size". If you are using a command which reads one line at a time, it will read even long lines, but if the input is more than one line, it will only read the first line.
Let's rephrase this problem. How do you know when something is more than one line? Because the next line is then not a date stamp. So you can create a simple parser for this format, which recognizes everything up to the next date stamp as one input record. This is probably best done with a scripting language such as awk or Perl or Python, but just for the sake of argument, here's a quick and dirty solution in shell script: Code:
#!/bin/sh
date=
input=
nl="
" # yes, that's opening quote, newline, closing quote
while read line; do
case $line in
*day\ [0-9][0-9]\ *\ [12][0-9][0-9][0-9]\ *)
# warning! y3k problem
# warning! fragile matching, would be better with regex
# warning! basically untested code anyway
case $date in '') ;;
*) echo "Result for '$date'":
echo "$input" ;;
esac
input=
date=$line
;;
*)
input="$input${input:+$nl}$line"
;;
esac
done
# whatever is left at end of file is a result too
echo "Result for '$date'":
echo "$input"
|
|
|||
|
Your question is not well-defined. Buffer size of what? What command are you using to read the output? If it has a limit on how long lines it will read, can you find a version which has no such limit?
(For example, the GNU coreutils tools are often better in this regard than whatever equivalent tools shipped with your commercial OS.) |
|||
| Google The UNIX and Linux Forums |
| Tags |
| perl, perl regex, regex |
| Thread Tools | |
| Display Modes | |
|
|