The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-16-2008
Registered User
 

Join Date: Feb 2008
Posts: 7
Stumble this Post!
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
First line contains informtation (date etc) and the 2nd line contains some information.

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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-17-2008
era
Guest
 

Posts: n/a
Stumble this Post!
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"
Reply With Quote
  #3 (permalink)  
Old 03-17-2008
Registered User
 

Join Date: Feb 2008
Posts: 7
Stumble this Post!
HI era,

Thanx for the reply.
Got your point. But is there anyway that we can increase the buffer size?
In SQL, we use 'set line 200'.. to achieve the same.

Thanks in advance.
Reply With Quote
  #4 (permalink)  
Old 03-17-2008
era
Guest
 

Posts: n/a
Stumble this Post!
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.)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
perl, perl regex, regex

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0