how to check by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to check by line
# 1  
Old 08-18-2008
how to check error line by line

Hello, Member or professional

need help how to check by line
Example of the file is here

HTML Code:
cdr20080817164322811681txt = 26 char
cdr20080917164322811txt = 23 char
cdr20081017164322811683txt = 26 char
cdr20081117164322811txt = 23 char
I want it to be is this

HTML Code:
cdr20080917164322811txt  is error
cdr20081117164322811txt  is error
*word of line that be not 26 char is error

Is anyone can help me?

Thank.

Last edited by ooilinlove; 08-18-2008 at 03:44 AM..
# 2  
Old 08-18-2008
Code:
perl -lne 'print "$ARGV:$.:error: $_" if (length != 26)' file

... or even simply

Code:
egrep -v '^.{26}$' file


Last edited by era; 08-18-2008 at 03:45 AM.. Reason: Provide egrep alternative, too
# 3  
Old 08-18-2008
it not work

example my log
logname vddd
inside mylog

cdr20080817164322811681txt
cdr20080817164322811681txt
cdr20080817164322811681txt
cdr20081117164322811txt
cdr20081117164322811txt
cdr20080817164322811681txt
cdr20080817164322811681txt
cdr20080817164322811681txt


HTML Code:
perl -lne 'print "$ARGV:$.:error: $_" if (length != 26)' vdddd 
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LC_ALL = (unset),
        LANG = "en_US"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
vdddd:4:error: cdr20081117164322811txt
vdddd:5:error: cdr20081117164322811txt
HTML Code:
or command egrep -v '^.{26}$' vdddd
result
cdr20080817164322811681txt
cdr20080817164322811681txt
cdr20080817164322811681txt
cdr20081117164322811txt
cdr20081117164322811txt
cdr20080817164322811681txt
cdr20080817164322811681txt
cdr20080817164322811681txt
# 4  
Old 08-18-2008
The warnings are unrelated. The Perl command printed what you wanted it to print (the last two lines of output; the output consists of file name, line number, "error: ", and the contents of the input line).

To work around the locale problem, you can use LC_ALL=C perl -lne ... but you should really see to it that your locale settings are fixed permanently; many applications will issue warnings about this problem, not just Perl. Perl is just a bit more verbose about it than many other applications.

The egrep command prints only the same two lines for me. Maybe you have DOS carriage returns or something in the input file? Or just spaces -- trailing spaces count as characters, too.

Code:
vnix$ egrep -v '^.{26}$' <<HERE
> cdr20080817164322811681txt
> cdr20080817164322811681txt
> cdr20080817164322811681txt
> cdr20081117164322811txt
> cdr20081117164322811txt
> cdr20080817164322811681txt
> cdr20080817164322811681txt
> cdr20080817164322811681txt
> HERE
cdr20081117164322811txt
cdr20081117164322811txt

# 5  
Old 08-18-2008
awk '(length($0)<26) {print($0 " is error")}' file
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

2. Shell Programming and Scripting

How to check line existence in shell ?

Hi, We have some config file and there we are looking to append a line if it is not found. abc.conf authpriv.* /var/log/secure mail.* -/var/log/maillog *.debug @vxhgt-hskhng02 cron.* ... (12 Replies)
Discussion started by: Litu19
12 Replies

3. Shell Programming and Scripting

How to check the number of columns in a line??

hi, i have a file with many records and each record may or may not have 6 columns. for example file1 : first second third fourth fifth sixth first second third fourth fifth first second third fourth fifth sixth first second third fourth fifth sixth seventh eigth if i cat the file and... (21 Replies)
Discussion started by: Little
21 Replies

4. Shell Programming and Scripting

Check if line has a space

Hi, I want to check if the given line from a text file has a spaces in between. if it does, then I want to add '"' double quotes at the beginning and end of the line. Otherwise leave the line as it is. For example, below is the sample content from my file. $cat file.txt test1 test2... (6 Replies)
Discussion started by: svajhala
6 Replies

5. Shell Programming and Scripting

help on shell script to check line

Hi Scripting Gurus, Can someone help to transform the below logic into a shell script, might be easy for some of you. I have a file with below text, I need if the line has the ":" and the above to it is not a blank line should print " <text>: is incorrect format" Apple: ... (3 Replies)
Discussion started by: usyseng
3 Replies

6. Shell Programming and Scripting

how to check if a new line has been added to a file?

Have come up with the following but it doesn't seem to work.. Is there some other command i could use to get this to work? OUTPATH=/home/out PARMFILE=$OUTPATH/jobcount_test.txt LOG=$OUTPATH/job_count_monthlymail_log.txt HLOG=$OUTPATH/job_count_monthlymail_hlog.txt # echo " started at... (2 Replies)
Discussion started by: Jazmania
2 Replies

7. Shell Programming and Scripting

check line by line in a file

Hi there How can I check line by line in a file? I need to compare the first value with the second to know if they are equal. If those values are equal, I require to send "TRUE" to the output or "FALSE" otherwise until the complete file has been read. Thank you (6 Replies)
Discussion started by: loperam
6 Replies

8. Shell Programming and Scripting

check line in a file

Hi all, How do we check in a file whether a line started with KEYWORD2 is right after the line started with KEYWORD1 for example, this file content: Abcdef gsh iasdi 94945 9085095 lksdjlkj KEYWORD1 skljfi slakjfoi ' opiport sdfl KEYWORD2 ksjflsk jfasope jkdfsk393 89374982 23 ... (3 Replies)
Discussion started by: fongthai
3 Replies

9. Shell Programming and Scripting

Check last line with gawk?

I am writing a gawk script that checks some basic code conformance rules (java text files) using gawk. So far, so good. But I have a requirement to ensure that the last line in the java source files is "/* eof */". The below snippet works BUT is called more than once per file as / / matches a... (3 Replies)
Discussion started by: sjf
3 Replies
Login or Register to Ask a Question