wc -c counts 1 char more per line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers wc -c counts 1 char more per line
# 1  
Old 06-14-2010
wc -c counts 1 char more per line

Hi,
this might be a basic question...
why is that wc -c counts 1 more per line than what is there.
for example,
> cat dum1.txt
123
12
> wc -c dum1.txt
7 dum1.txt


Thanks,
Sameer.
# 2  
Old 06-14-2010
Check the number of characters in your file
Code:
$cat -e file_name

wc -c showing that count.
# 3  
Old 06-14-2010
There are 7 characters in dum1.txt. You are missing to take the newlines into account.
# 4  
Old 06-14-2010
The "extra" character is the newline at the end of both lines: 5 printable characters ("123" and "12") plus 2 newlines = 7.

Visual example (the blue line is inserted by me and not part of the original output):
Code:
$ cat dum1.txt
123
12
$ wc -c dum1.txt
7 dum1.txt
$ xxd dum1.txt
          1 2  3\n  1 2 \n
0000000: 3132 330a 3132 0a                        123.12.

# 5  
Old 06-14-2010
Code:
# od -c dum1.txt
0000000   1   2   3  \n   1   2  \n
0000007

123+n+12+n=7 Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicated records and update last line record counts

Hi Gurus, I need to remove duplicate line in file and update TRAILER (last line) record count. the file is comma delimited, field 2 is key to identify duplicated record. I can use below command to remove duplicated. but don't know how to replace last line 2nd field to new count. awk -F","... (11 Replies)
Discussion started by: green_k
11 Replies

2. Shell Programming and Scripting

Avoiding new line for the counts

Hi Team, Am getting the below output but need the count of records to be displayed in same line but currently count alone moves to next line. Please let me know how we can still keep the count in the same line. ######code ##### while read YEAR; do for i in TEST_*PGYR${YEAR}_${DT}.csv; do... (3 Replies)
Discussion started by: weknowd
3 Replies

3. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

4. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

5. Shell Programming and Scripting

Add new line after ' char

Hello experts, I need to convert one file into readable format. Input file is like following line. STG,12345,000,999,' PQR, 2345,000,999,' XYZ,7890,000,999, Output should be following (After ' char new line char should be added.) STG,12345,000,999,' PQR, 2345,000,999,' ... (16 Replies)
Discussion started by: meetmedude
16 Replies

6. Shell Programming and Scripting

Add char before certain line

I'm trying to add a '1' before a line that has the word "C_ID" s/.*C_ID.*/&\n1/ The above code did what I need, but the '1' is added after the C_ID word :( Help please. (5 Replies)
Discussion started by: newbeee
5 Replies

7. Shell Programming and Scripting

word counts for a single line xml file

I have any XML ouput file(file name TABLE.xml), where the data is loaded in A SINGLE LINE, I need help in writting a ksh shell script which gives me the word counts of word <TABLE-ROW> This is my input file. <?xml version="1.0" encoding="UTF-8"?><!--Generated by Ascential Software... (4 Replies)
Discussion started by: pred55
4 Replies

8. Shell Programming and Scripting

how first char in odd line and second char in even line

Hi I m having ifconfig -a o/p like sbanlab1:ksh# ifconfig -a | egrep "flags|inet" | awk -F' ' '{print $1,$2}' lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 bge0:... (1 Reply)
Discussion started by: tarunn.dubeyy
1 Replies

9. Shell Programming and Scripting

extraction of last but one char in a line

I need to extract the character before the last "|" in the following lines, which are 'N' and 'U'. The last "|" shouldn't be extracted. Also the no.s of "|" may vary in a line, but I need only the character before the last one. ... (1 Reply)
Discussion started by: hidnana
1 Replies
Login or Register to Ask a Question