Sponsored Content
Top Forums Shell Programming and Scripting parse a file for a special character Post 302244968 by a2156z on Thursday 9th of October 2008 04:25:34 AM
Old 10-09-2008
Check some entry commented not or not
grep -n "$entry_name" "$file_name" | awk '$2~/^#/{print $2, "Line", $1"is commented"}'
Check some line commented or not
awk '$0 ~/^#/{if( NR == "$line_num" ) printf("commented: 5d\n", NR);}

Last edited by a2156z; 10-09-2008 at 05:34 AM..
a2156z
 

9 More Discussions You Might Find Interesting

1. Solaris

Mount a character special file

Hi together I have 2 systems, mars and venus. The configuration is the same. Every system has a SDLT. I will now backup the datas from mars on the tapedevice from venus. I have shareed the tapedevice (venus) and mounted on mars. Now my problem: when I write on the mountet tapedevice, the... (1 Reply)
Discussion started by: MuellerUrs
1 Replies

2. Shell Programming and Scripting

delete a special character in file

hi i want to delete a particular character in file. example file name:abcsample abc=bbbqw3/ hidh=ajjqiwio4/ xyx=hakjp/ ........../ ......./ i want to delete that special character (/) in abcsample file.please give the required commands for my requirement. thank you (3 Replies)
Discussion started by: srivsn
3 Replies

3. Shell Programming and Scripting

delete a special character in file

hi i want to delete a particular character in file. example file name:abcsample abc=bbbqw3/ hidh=ajjqiwio4/ xyx=hakjp/ ........../ ......./ i want to delete that special character (/) in abcsample file Permnently.please give the required commands for my requirement. required... (1 Reply)
Discussion started by: srivsn
1 Replies

4. UNIX for Dummies Questions & Answers

Special character in my file

I have a special character in my file. It displays as a '#' sign but when I do this command I do not find the line. fgrep 'G#ant' file1 I want to replace the special character with another value but I need to know what character it really is. Any ideas on how to replace this '#' value with... (3 Replies)
Discussion started by: Ryan2786
3 Replies

5. Shell Programming and Scripting

parse special character in the line

Hi all, I have a file with some module names as below. Font::AFM Data::Grove ---> libxml-perl Net::LDAP ---> perl-ldap DBI XML .... ... .... and so on ... The file has some lines with the character " -->" . Now how can I cut only the last column of the line wherever "-->" is... (4 Replies)
Discussion started by: vijaya2006
4 Replies

6. Shell Programming and Scripting

Removing Special Character from File.

Hi, My file has this special character "^M" I would like to remove this characters. eg: abc,abc,^M i tried using sed but doesnt work. i used octal dump command to see special character it returns following: 015 \r Appreciate your reply. (6 Replies)
Discussion started by: pinnacle
6 Replies

7. Shell Programming and Scripting

Remove special character ($) from file names

Hello I've searched here and on the 'net for examples of a script or command line function that will remove the $ character from all file names only that can be done within the directory that contains the file names - which are all html files. ie, I have a directory that contains html files... (6 Replies)
Discussion started by: competitions
6 Replies

8. Programming

Problem with control file and special character

I am getting error when loading data file using ctl file. I get this error only when there is special character. Below is some data. DataFile=> company_id|ciu_id|english_name|iso_country_code|active|partner_name 1-2JT-122||Expert Järvenpää|FI|A|Expert Järvenpää Control File=> LOAD DATA... (1 Reply)
Discussion started by: rshivarkar
1 Replies

9. Red Hat

Special character ^@ in CSV file

All, I am having a tough time with Linux and CSV file. My CSV file gets generated from Cognos on Linux machine that contains special characters. At first instance when I do vi <filename> to that file, I can't see anything. I did tail -2 and redirected to another temp file and did vi <filename>,... (2 Replies)
Discussion started by: donadarsh
2 Replies
pmccabe(1)						      General Commands Manual							pmccabe(1)

NAME
pmccabe - calculate McCabe cyclomatic complexity or non-commented line counts for C and C++ programs SYNOPSIS
pmccabe [-bCdfFntTvV?] [file(s)] DESCRIPTION
pmccabe processes the named files, or standard input if none are named. In default mode it calculates statistics including McCabe cyclo- matic complexity for each function. The files are expected to be either C (ANSI or K&R) or C++. -? Print an informative usage message. -v Print column headers -V Print pmccabe version number De-commenting mode -d Intended to help count non-commented source lines via something like: pmccabe -d *.c | grep -v '^[<blank><tab>]*$' | wc -l Comments are removed, cpp directives are replaced by cpp, string literals are replaced by STRINGLITERAL, character constants are replaced by CHARLITERAL. The resulting source code is much easier to parse. This is the first step performed by pmccabe so that its parser can be simpler. None of the other options work sensibly with -d. Line-counting mode -n Counts non-commented source lines. The output format is identical to that of the anac program except that column headers and totals must be requested if desired. If you want column headers add -v. If you want totals add -t. If all you want is totals add -T. Complexity mode (default) -C Custom output format - don't use it. -c Report non-commented, non-blank lines per function (and file) instead of the raw number of lines. Note that pre-processor direc- tives are NOT counted. -b Output format compatible with compiler error browsing tools which understand "classic" compiler errors. Numerical sorting on this format is possible using: sort -n +1 -t% -t Print column totals. Note the total number of lines is *NOT* the number of non-commented source lines - it's the same as would be reported by "wc -l". -T Print column totals *ONLY*. -f Include per-file totals along with the per-function totals. -F Print per-file totals but NOT per-function totals. Parsing pmccabe ignores all cpp preprocessor directives - calculating the complexity of the appearance of the code rather than the complexity after the preprocessor mangles the code. This is especially important since simple things like getchar(3) expand into macros which increase com- plexity. Output Format A line is written to standard output for each function found of the form: Modified McCabe Cyclomatic Complexity | Traditional McCabe Cyclomatic Complexity | | # Statements in function | | | First line of function | | | | # lines in function | | | | | filename(definition line number):function | | | | | | 5 6 11 34 27 gettoken.c(35): matchparen Column 1 contains cyclomatic complexity calculated by adding 1 (for the function) to the occurences of for, if, while, switch, &&, ||, and ?. Unlike "normal" McCabe cyclomatic complexity, each case in a switch statement is not counted as additional complexity. This treatment of switch statements and complexity may be more useful than the "normal" measure for judging maintenance effort and code difficulty. Column 2 is the cyclomatic complexity calculated in the "usual" way with regard to switch statements. Specifically it is calculated as in column 1 but counting each case rather than the switch and may be more useful than column 1 for judging testing effort. Column 3 contains a statement count. It is calculated by adding each occurence of for, if, while, switch, ?, and semicolon within the function. One possible surprise is that for statements have a minimum statement count of 3. This is realistic since for(A; B; C){...} is really shorthand for A; while (B) { ... C;}. The number of statements within a file is the sum of the number of statements for each func- tion implemented within that file, plus one for each of those functions (because functions are statements too), plus one for each other file-scoped statement (usually declarations). Column 4 contains the first line number in the function. This is not necessarily the same line on which the function name appears. Column 5 is the number of lines of the function, from the number in column 4 through the line containing the closing curly brace. The final column contains the file name, line number on which the function name occurs, and the name of the function. APPLICATIONS
The obvious application of pmccabe is illustrated by the following which gives a list of the "top ten" most complex functions: pmccabe *.c | sort -nr | head -10 Many files contain more than one C function and sometimes it would be useful to extract each function separately. matchparen() (see exam- ple output above) can be extracted from gettoken.c by extracting 27 lines starting with line 34. This can form the basis of tools which operate on functions instead of files (e.g., use as a front-end for diff(1)). DIAGNOSTICS
pmccabe returns a nonzero exit status if files could not be opened and upon encountering some parsing errors. Error messages to standard error, usually explaining that the parser is confused about something, mimic classic C compiler error messages. WARNINGS
pmccabe is confused by unmatched curly braces or parentheses which sometimes occur with hasty use of cpp directives. In these cases a diagnostic is printed and the complexity results for the files named may be unreliable. Most times the "#ifdef" directives may be modified such that the curly braces match. Note that if pmccabe is confused by a cpp directive, most pretty printers will be too. In some cases, preprocessing with unifdef(1) may be appropriate. Statement counting could arguably be improved by: counting occurences of the comma operator, multiple assignments, assignments within con- ditional tests, and logical conjunction. However since there is no crisp statement definition from the language or from people I've queried, statement counting will probably not be improved. If you have a crisp definition I'll be happy to consider it. Templates cause pmccabe's scanner to exit. It's a shame that ctags output isn't provided. AUTHOR
Paul Bame SEE ALSO
codechanges(1), decomment(1), vifn(1), sort(1), diff(1), wc(1), grep(1), unifdef(1), head(1), anac(1) http://parisc-linux.org/~bame/pmccabe/ HP
12Feb2003 pmccabe(1)
All times are GMT -4. The time now is 07:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy