Grep: line too long error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep: line too long error
# 1  
Old 11-17-2016
Tools Grep: line too long error

Hi,
Code:
 cat server.out | grep user1
           
  grep: line too long

I tried grep -o, grep -z and cat server.out | grep user1 > output.txt

Code:
               uname -a
  Linux mymac 2.6.18-410.el5 #1 SMP Fri Apr 8 05:48:52 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

Can you please help me resolve the
Code:
grep: line too long


Last edited by Don Cragun; 11-17-2016 at 11:28 PM.. Reason: Get rid of FONT and COLOR tags inside CODE tags.
# 2  
Old 11-17-2016
Code:
sed -n '/user1/p' server.out

# 3  
Old 11-17-2016
What is server.out ? I'm guessing its lines are too long. Is it really a text file? Binary files can cause this error.

You don't need to use cat here, but that's unrelated to your error.
# 4  
Old 11-17-2016
does the line begin with user1? does it end with it? do you have a sample line that includes this user1 record? Will user1 always be lower case or could it be mixed case?

And as Corona688 said, you don't need to cat the file first. A simple grep will suffice. Simplify the command as well:

Code:
grep -i user1 server.out

# 5  
Old 11-17-2016
sysconf LINE_MAX will show the line limit for UNIX tools. It used to be a default 2048 bytes on older systems,.
# 6  
Old 11-18-2016
Hi.

On systems like:
Code:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie)

This may work:
Code:
getconf Query system configuration variables (man)
Path    : /usr/bin/getconf
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with --help

Such as:
Code:
$ getconf LINE_MAX       
2048

Best wishes ... cheers, drl

---------- Post updated at 09:36 ---------- Previous update was at 09:11 ----------

Hi.
Quote:
Originally Posted by mohtashims
... [/CODE]Can you please help me resolve the
Code:
grep: line too long

So what is a satisfactory resolution?

Do you wish to create line breaks -- add newlines -- in the file?

Do you wish to simply look at the neighborhood of the matched pattern?

If the latter, command bool may be able to help:
Code:
bool    print context matching a boolean expression (man)
Path    : ~/executable/bool
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with [     ]-h,--help
Home    : https://www.gnu.org/software/bool/

Best wishes ... cheers, drl
# 7  
Old 11-19-2016
What is the format of the lines?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vi editor Line too Long Error

My file is 13 mb but it has big long lines. i tried in vain vi -R filename I tried in vainbash: vim: command not found SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4vCan you please suggest? (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

grep : Argument list too long

Hi, i am having some trouble with the below command, can some one suggest me the better way to do it. grep -l 'ReturnCode=1' `find $Log -newer /tmp/Failed.tmp -print | xargs ls -ld | egrep SUB | egrep -ve 'MTP' -ve 'ABC' -ve 'DEF' -ve 'JKL' -ve 'XYZ' | awk '{print $9}'` > $Home1 Its... (2 Replies)
Discussion started by: Prateek007
2 Replies

3. Shell Programming and Scripting

How to grep the line with error where keyword in next line is known.

If a file consists of a thousands of line. There is a error line in the file which exists just before the line with word "Manish". How could I write a script to grep the line with error. Ex:- If I have a UNIX file which contains the following: bash-3.2$ cat unix.txt Unix (officially... (4 Replies)
Discussion started by: manishdivs
4 Replies

4. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

5. UNIX for Dummies Questions & Answers

vi : Line too Long Error

Hi ! I am woking on Solaris 5.10 and face a problem sometimes when i try to open files in the vi editor . Sometime when the file is big i am not able to view the file in vi and i get the error like I guess vi have some line size setting and if the lines are ,longer than that... (4 Replies)
Discussion started by: Paarth
4 Replies

6. UNIX for Dummies Questions & Answers

grep long line

I am trying to get the count of a word from an xml using the below command grep "search word" -c test.xml The result is only 1, because my xml contains only one line (hule line- several thousand characters). I guess grep command will process for only 128 characters for each line. ... (7 Replies)
Discussion started by: venky23
7 Replies

7. Shell Programming and Scripting

grep/matching help with long listing of directories

How do I get this to work? cat somefile | grep "-rw-r--r-- 1 root wheel 287 Sep 10 15:12 shells~" This is the the desired output -rw-r--r-- 1 root wheel 287 Sep 10 15:12 shells~ I basically want an exact match of the line I am grepping for, the special characters and... (5 Replies)
Discussion started by: streetfighter2
5 Replies

8. Shell Programming and Scripting

a better way to grep until end of error message, although most seem to be 1 or 2 line

My file creates an output log after which includes a few sql queries. I segregate them into warnings and errors and then get a total count. The errors' and warnings' lines always start with SQL{4} followed by the details of the error. This is what im doing as o now... errors=`grep -A 1 -E... (11 Replies)
Discussion started by: VGR
11 Replies

9. Shell Programming and Scripting

grep : search a long char contain space

Hi, i have to search for a char like that : export var1="i am not happy /not happy" with a command like : grep $var1 file but this not working with me !!! thank you in advance. (2 Replies)
Discussion started by: tizilfin
2 Replies

10. Shell Programming and Scripting

getting error 0403-016 Cannot find or open the file while reading a long line

Hi, I have an requirement of reading a long line of 7000 chars and cutting it iam doing this : while read -r x do echo $x ......... done < `cat filename` when iam doing this it is giving me "0403-016 Cannot find or open the file." Can anyone let how this can be done. (2 Replies)
Discussion started by: karthee
2 Replies
Login or Register to Ask a Question