Problems while read a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems while read a file
# 1  
Old 06-23-2008
Error Problems while read a file

Hello guys, i need your help, let me try to explain what i need:

I have a file (plain text) for example with 500 lines, i need to read only from the line 200 until the end of file, and serch the word 'ERROR' onli between lines 200 and 500, that have sence?

Thanx for your help.
# 2  
Old 06-23-2008
We understand what you need, however can you post what you have tried so far and to let us see where you're at and we'll see how we can assist.
# 3  
Old 06-23-2008
Quick solution..

A quick solution is
sed -n '200,$p' file | grep ERROR
Thanks,
CSS
# 4  
Old 06-23-2008
Quote:
Originally Posted by lestat_ecuador
.. and serch the word 'ERROR' onli between lines 200 and 500, that have sence?

@sudhamacs
check the OP request.
# 5  
Old 06-23-2008
Thanx

Thanx sudhamacs , however, i need to set the start line (in this case 200) by paramether, i mean, i have the number of line to start my search in a variabla names LINEA, but there is an error if i try:

sed -n '$LINEA,$p' file | grep ERROR
# 6  
Old 06-23-2008
Bug

if you need to use variable then use double quotes instead of single quote for the value of the variable to effect.

sed -n "$LINEA,$ p" file | grep ERROR

Also note that there is a space between $ and p.
$ means the end of the file
p means print

if you don't want to search till end of the file, i.e. you want to search till line 500 then you can replace $ with 500, or with a variable.

Thanks,
CSS
# 7  
Old 06-23-2008
I don't think that sed + grep is the right direction, anyway awk can sed and grep. What about:
Code:
awk 'NR >= "'"$LINEA"'" && NR <= "'"$LINEB"'" && /ERROR/' data.file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

2. Programming

File upload problems

When I upload image files they have the same extension twice. And my script doesn't show it even it the path is correct. Some scripts copy the file from the tmp dir server to the required directory, while others just move it. What happens to the files that were just copied? Do they stay... (1 Reply)
Discussion started by: AimyThomas
1 Replies

3. Ubuntu

Problems with a .sh file in cron

Hi guys. This is my first post so bear with me. I'm trying to get cron to run a shell script in my home directory (/home/server) that checks the temperature of my HDD. The script works fine, however I can't run it in cron. I've checked the syslog and I have only seen two errors: - Exited with... (11 Replies)
Discussion started by: Rautoner
11 Replies

4. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

5. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

6. Shell Programming and Scripting

Problems restraining read command to 32 bits -perl

Hey everybody, I'm having difficulty using the read command to perform a checksum operation. Whenever I print the final checksum, the result always returns FFFFFFFF, and I know thats not the checksum. #!/usr/bin/perl -w use strict; use FileHandle; use warnings; my $data... (0 Replies)
Discussion started by: TeamUSA
0 Replies

7. Shell Programming and Scripting

Read a file and search a value in another file create third file using AWK

Hi, I have two files with the format shown below. I need to read first field(value before comma) from file 1 and search for a record in file 2 that has the same value in the field "KEY=" and write the complete record of file 2 with corresponding field 2 of the first file in to result file. ... (11 Replies)
Discussion started by: King Kalyan
11 Replies

8. Programming

Cannot read a file with read(fd, buffer, buffersize) function

# include <stdio.h> # include <fcntl.h> # include <stdlib.h> # include <sys/stat.h> int main(int argc, char *argv) { int fRead, fPadded, padVal; int btRead; int BUFFSIZE = 512; char buff; if (argc != 4) { printf ("Please provide all of the... (3 Replies)
Discussion started by: naranja18she
3 Replies

9. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

10. UNIX for Advanced & Expert Users

File system problems

Hi All, I am currently running Linux on a file server. The server starts experiencing problems (slow access, no access). After a shutdown and reboot, the file system is corrupted and requires to run fsck to clean up. Is this signs of a failing hard drive? Ken (2 Replies)
Discussion started by: kmcvey
2 Replies
Login or Register to Ask a Question