Sponsored Content
Top Forums Shell Programming and Scripting Find Special/Null/Control Chars and Print Line Numbers Post 302845003 by DGPickett on Tuesday 20th of August 2013 02:32:43 PM
Old 08-20-2013
Hardest first: null is not handled by most tools. 'cat -v' can turn it into '^@' C/C++/PERL/JAVA/etc. can read byte by byte and translate anything. grep can print line numbers and lines containing [^ -~] (not between the space and tilde characters, the ASCII non-control characters).

Text does not normally have such, so the concept of lines and line numbers is funny. File names are in directories not flat files, generally, but a flat file could have a file name in it, if you can figure out how to frame it. Are you describing a process ot examine many files?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to print out line numbers of a text file?

i have this text file name test.txt which contain : aaaaa bbb iiiiiiiiiiiii ccf ddaaa ddd and i need a script that can print out the line numbers using a while loop.. so when the script is run..it will have this: 1 2 3 any ideas? :) thanks guys (4 Replies)
Discussion started by: forevercalz
4 Replies

2. Shell Programming and Scripting

Help required in displaying lines exceeding 79 chars along with their line numbers ??

Hi folks, I am looking for a solution to display those lines in any file that contains 80 or more characters along with their corresponding line number in the file. The below script will print the lines with their corresponding line numbers... sed = Sample.cpp | sed 'N;s/\n/\t/;... (8 Replies)
Discussion started by: frozensmilz
8 Replies

3. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

4. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

5. Shell Programming and Scripting

To Generate control chars[^M, ^C etc]

Hi Experts, Please let me know, how to generate control characters in a file. I want to test my script which will check for any control characters in a file before loading the data into the PRD Database. Thanks in Advance, Sapy. (2 Replies)
Discussion started by: saps19
2 Replies

6. Shell Programming and Scripting

print all between patterns with special chars

Hi, I'm having trouble with awk print all characters between 2 patterns. I tried more then one solution found on this forum but with no success. Probably my mistakes are due to the special characters "" and "]"in the search patterns. Well, have a log file like this: logfile.txt ... (3 Replies)
Discussion started by: ginolatino
3 Replies

7. Shell Programming and Scripting

Find common numbers and print yes or no

Hi I have 2 files with following data First file, sp|Q676U5|A16L1_HUMAN, Autophagy-related protein 16-1 OS=Homo sapiens GN=ATG16L1 PE=1 SV=2, Maximum coiled-coil residue probability: 0.657 in position 163. Maximum dimeric residue probability: 0.288 in position 163. ... (1 Reply)
Discussion started by: manigrover
1 Replies

8. UNIX for Dummies Questions & Answers

Grep with special chars line by line

I have a file that includes strings with special characters, eg file1 line: 1 - special 1 line: = 4 line; -3 etc How can I grep the lines of file1 from file2, line by line? I used fgrep and egrep to grep a particular line and worked fine, but when I used: cat file1|while read line;do... (2 Replies)
Discussion started by: FelipeAd
2 Replies

9. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

10. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies
wc(1)							      General Commands Manual							     wc(1)

NAME
wc - Counts the lines, words, characters, and bytes in a file SYNOPSIS
wc [-c | -m] [-lw] [file...] The wc command counts the lines, words, and characters or bytes in a file, or in the standard input if you do not specify any files, and writes the results to standard output. It also keeps a total count for all named files. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: wc: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Counts bytes in the input. Counts lines in the input. Counts characters in the input. Counts words in the input. OPERANDS
Specifies the pathname of the input file. If this operand is omitted, standard input is used. DESCRIPTION
A word is defined as a string of characters delimited by white space as defined in the X/Open Base Definitions for XCU4. The wc command counts lines, words, and bytes by default. Use the appropriate options to limit wc output. Specifying wc without options is the equivalent of specifying wc -lwc. If any options are specified, only the requested information is output. The order in which counts appear in the output line is lines, words, bytes. If an option is omitted, then the corresponding field in the output is omitted. If the -m option is used, then character counts replace byte counts. When you specify one or more files, wc displays the names of the files along with the counts. If standard input is used, then no file name is displayed. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To display the number of lines, words, and bytes in the file text, enter: wc text This results in the following output: 27 185 722 text The numbers 27, 185, and 722 are the number of lines, words, and bytes, respectively, in the file text. To display only one or two of the three counts include the appropriate options. For example, the following command displays only line and byte counts: wc -cl text 27 722 text To count lines, words, and bytes in more than one file, use wc with more than one input file or with a file name pat- tern. For example, the following command can be issued in a directory containing the files text, text1, and text2: wc -l text* 27 text 112 text1 5 text2 144 total The numbers 27, 112, and 5 are the numbers of lines in the files text, text1, and text2, respectively, and 144 is the total number of lines in the three files. The file name is always appended to the output. To obtain a pure number for things like reporting purposes, pipe all input to the wc command using cat. For example, the following command will report the total count of characters in all files in a directory. echo There are `cat *.c | wc -c` characters in *.c files There are 1869 characters in *.c files ENVIRONMENT VARIABLES
The following environment variables affect the execution of wc: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files) and which characters are defined as white space characters. Determines the locale for the format and contents of diagnostic messages written to standard error and informative messages written to standard output. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: cksum(1), ls(1) Standards: standards(5) wc(1)
All times are GMT -4. The time now is 12:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy