grep long line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep long line
# 1  
Old 01-28-2010
grep long line

I am trying to get the count of a word from an xml using the below command
Code:
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.

Could anyone pls help me?

Last edited by vbe; 01-28-2010 at 01:14 PM.. Reason: code tags...
# 2  
Old 01-28-2010
The result is one because there is only one line that contains such pattern.

See:
Code:
$ echo "dog dog" | grep -c "dog"
1

# 3  
Old 01-28-2010
You can do something like:

Code:
$ echo "dog dog" | tr " " "\n" |grep -c "dog"
2

# 4  
Old 01-28-2010
@Franklin52:
Yes, but this will not allow to search for phrases like the original example suggest ('search word').
# 5  
Old 01-28-2010
Quote:
Originally Posted by dpc.ucore.info
@Franklin52:
Yes, but this will not allow to search for phrases like the original example suggest ('search word').
In that case:

Code:
awk '{print gsub("search word","")}' file

# 6  
Old 01-28-2010
Code:
$echo "search word search word" | awk '{print gsub("search word","")}'
awk: syntax error near line 1
awk: illegal statement near line 1

I've tried to check it. Can you help Franklin52 as I'm leaving for few hours.
# 7  
Old 01-28-2010
Quote:
Originally Posted by dpc.ucore.info
Code:
$echo "search word search word" | awk '{print gsub("search word","")}'
awk: syntax error near line 1
awk: illegal statement near line 1

I've tried to check it. Can you help Franklin52 as I'm leaving for few hours.
Use nawk or /usr/xpg4/bin/awk on Solaris.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep: line too long error

Hi, cat server.out | grep user1 grep: line too long I tried grep -o, grep -z and cat server.out | grep user1 > output.txt 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... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Dummies Questions & Answers

Getting parameter list is too long in grep command

Hi i am getting below message while using grep command "The parameter list is too long" grep -i 919716499889 * ksh: /usr/bin/grep: 0403-027 The parameter list is too long. please let me know what changes i can do in this command (5 Replies)
Discussion started by: scriptor
5 Replies

3. 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

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. 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

6. 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

7. Shell Programming and Scripting

Grep causing long delay (batching) whilst piping

Hi all. I have a problem at work which I have managed to break down into a simple test scenario: I have written a monitoring script that outputs every second the status of various processes, but for now, lets just print the date input.sh: while true do date sleep 1 done This... (9 Replies)
Discussion started by: spudtheimpaler
9 Replies

8. UNIX for Dummies Questions & Answers

vi.....line too long

I'm getting a "line too long" error when I try to vi a particular file. I really just need to view the contents as I don't have to change anything. Any suggestions?? I already tried to cat but it didnt work........:( (7 Replies)
Discussion started by: shorty
7 Replies

9. Shell Programming and Scripting

ksh: /bin/grep: arg list too long

when i run the command below in a directory which contains too many files i got the error: ksh: /bin/grep: arg list too long ls|grep AA*B* how can i handle this problem? (5 Replies)
Discussion started by: gfhgfnhhn
5 Replies

10. UNIX for Dummies Questions & Answers

Grep 0403-027 The parameter list is too long.

Hi there I get this error message when I try to do a basic grep. Does anyone have any ideas what is wrong. Thanks 0403-027 The parameter list is too long. (1 Reply)
Discussion started by: japada
1 Replies
Login or Register to Ask a Question