Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Use portion of file name as new file name Post 302988096 by RudiC on Tuesday 20th of December 2016 09:38:54 AM
Old 12-20-2016
PLEASE copy AS IS - do not interfere without knowing EXACTLY WHAT you are doing. DON'T concatenate the statements from multiple lines into one line without additional measures (e.g. adding a semicolon).
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove portion of file

Can anyone tell me how to remove a portion of a large file to smaller ones? What I have is a large file that was created becasue several similar files were joined together. Each individual file starts with MSG_HEAD. I want to take everything from MSG_HEAD up to were it says MSG_HEAD again and... (13 Replies)
Discussion started by: methos
13 Replies

2. Shell Programming and Scripting

Separate a portion of text file into another file

Hi, I have my input as follows : I have given two entries- From system Mon Aug 1 23:52:47 2005 Source !100000006!: Impact !100000005!: High Status ! 7!: New Last Name+!100000001!: First Name+ !100000003!: ... (4 Replies)
Discussion started by: srikanth_ksv
4 Replies

3. Programming

Delete Portion of a file

hi i would like to know whether i can delete a part of a file in C for eg. if my file contained 1234567890 and i want to delete 456 so that it becomes 1237890 is there a way i can do this. well, one way i can achieve this is by creating a new file, copy whatever i want, then delete the... (2 Replies)
Discussion started by: sameersbn
2 Replies

4. UNIX for Dummies Questions & Answers

Print a portion of file

Hi, I have a little problem. I am having a file with pattern like : asdf;ffgg;dfjfj;djdfjf;nnjj;djd;ssj; I just want to print the portion from last ";" upto the immediate previous ";". There are several ";" in my line. Please help me out... Thnx in advance (8 Replies)
Discussion started by: vanand420
8 Replies

5. Shell Programming and Scripting

Grep certain portion from the file

Dear Friends, Here I am with another difficulty. I have a flat file from which I wanna grep following pattern. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Statement Date : Blah blah Blah blah Blah blah Blah blah... (1 Reply)
Discussion started by: anushree.a
1 Replies

6. UNIX for Dummies Questions & Answers

Portion of a file in a new files

Hi, I need to devide one file into 3 files based on column numbers and put a string (FILE1, FILE2, FILE3) in the last..... Input file: Column1,Column2,Column3,Column4,Column5,Column6,Column7,Column8,Column9,Column10 Output1: Column1,Column3,Column6,Column4,Column5,FILE1 Output2:... (6 Replies)
Discussion started by: yale_work
6 Replies

7. Shell Programming and Scripting

Rename portion of file based on another file

Hello, I've been searching and reading, but I can't figure out how to solve this problem with my newbie skills. In my directory, I have a list of files (see dirlist.txt attachment) that I need to merge and rename. I have part of the code of the code figured out (see below). However, I... (3 Replies)
Discussion started by: anjulka
3 Replies

8. UNIX for Advanced & Expert Users

Removing portion of file name

Hi , I am getting file name like ABC_DATA_CUSTIOMERS_20120617.dat ABC_DATA_PRODUCTS_20120617.dat Need to convert CUSTIOMERS.dat PRODUCTS.dat Help me how to do this. (7 Replies)
Discussion started by: reach_malu
7 Replies

9. Shell Programming and Scripting

Unix Scripting : Sort a Portion of a File and not the complete file

Need to sort a portion of a file in a Alphabetical Order. Example : The user adam is not sorted and the user should get sorted. I don't want the complete file to get sorted. Currently All_users.txt contains the following lines. ############## # ARS USERS ############## mike, Mike... (6 Replies)
Discussion started by: evrurs
6 Replies

10. UNIX for Dummies Questions & Answers

How to append portion of a file content to another file when a certain pattern is matching?

Hi ladies and gentleman.. I have two text file with me. I need to replace one of the file content to another file if one both files have a matching pattern. Example: text1.txt: ABCD 1234567,HELLO_WORLDA,HELLO_WORLDB DCBA 3456789,HELLO_WORLDE,HELLO_WORLDF text2.txt: XXXX,ABCD... (25 Replies)
Discussion started by: bananamen
25 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 09:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy