Questions tagged [wc]

`wc` is a standard POSIX command that counts words, lines, and characters.

The wc utility reads one more files (or the standard input) and writes the number of lines, words, and characters to the standard output. If more than one file is given, then the total number of lines, words, and characters across all inputs will also be printed. There are also switches for controlling what parts should be counted.

Some versions of wc can differentiate between characters (which may be multi-byte depending on the encoding) and bytes.

References:

350 questions
0
votes
2 answers

WIN32 - Reading Text File In MyDocuments In Windows CE Returning Blank

I am trying to write a simple program to READ a text file named "1.txt" (which contains just "abc") in Windows CE OS using Windows Mobile 5.0 SDK, WIN32 and C in Visual Studio 2008. I have stored this text file in My Documents folder. My program is…
Ezani
  • 535
  • 3
  • 18
0
votes
3 answers

Sorting after using wc on files from a directory

Specify a command / set of commands that displays the number of lines of code in the .c and .h files in the current directory, displaying each file in alphabetical order followed by: and the number of lines in the files, and finally the total of the…
JonBjatBun
  • 39
  • 5
0
votes
1 answer

Watch and wc not yielding any results

I try to constantly display the size of the current folder using watch , the below command does not work however, what do I do wrong ? I use zsh shell $ watch ls -a | wc -l
baconStrips
  • 101
  • 9
0
votes
1 answer

Display files with inode number between 100 and 199 in specific directory

I am trying to find all the files with inode number between 100 and 199. I tried it with wildcards like this: ls -i -l 1* | wc -l
stefanp99
  • 5
  • 2
0
votes
0 answers

File redirection before command

I tested two commands that produce the same output: $ wc -l < input_file 6 $ < input_file wc -l 6 The first command redirects input_file to stdin which is then read by wc. I don't understand the second command and would appreciate an explanation.
builder-7000
  • 7,131
  • 3
  • 19
  • 43
0
votes
3 answers

Remove half the lines of files recursively using sed and wc

I wonder if there is a way to remove half the lines of a file using wc and sed. I can do this: sed -i '50,$d' myfile.txt Which removes lines from 50 to the end of file. I can also do this: wc -l myfile.txt Which returns the number of lines in the…
danielrvt
  • 10,177
  • 20
  • 80
  • 121
0
votes
4 answers

Get the line number of the last line with non-blank characters

I have a file which has the following content: 10 tiny toes tree this is that tree 5 funny 0 There are spaces at the end of the file. I want to get the line number of the last row of a file (that has characters). How do I do that in SED?
0
votes
1 answer

Bash script that count files using wc but making it exit if count does not match as expected

I have the following folder structure: files ├── 0 │   ├── textfile1.txt │   ├── textfile2.txt files ├── 1 │   ├── textfile1.txt │   ├── textfile2.txt files ├── 2 │   ├── textfile1.txt │   ├── textfile2.txt and to count the text files in each…
Saffik
  • 911
  • 4
  • 19
  • 45
0
votes
0 answers

How to use linux wc command with char array?

Hi~ I'm just making sample program which implements pipe command. In this program, I'm trying to implement "cat somefile.txt | wc" command.. So I called fork() twice, I used first child process for sending results of "cat somefile.txt" to…
Carim
  • 1
  • 3
0
votes
0 answers

count number of lines from apt output

As part of learning/experimenting with bash I wrote a script with which you can install android-tools-adb package. apt output is written to log file. Before and after I run apt install, I check number of lines in log file, so I can check lines later…
mauek unak
  • 702
  • 2
  • 11
  • 28
0
votes
1 answer

Sed not replacing new line pattern in text file

I've got a txt file that I've retrieved from SQL Server Manager and hence the line delimitor is '\r\n'. I would like to change this line delimitor to '\n'. You can see my approach below. The problem is that even afer running the sed, it looks like…
callmeGuy
  • 944
  • 2
  • 11
  • 28
0
votes
0 answers

Using pidof pipe with wc -l in Bash does not return expected 0 value

Scenario I'm trying add the following flag before the execution of main process in shell script to make sure that this script is running only once at a time by checking the number of pids of same-name script: this_bash=$(basename…
ceoper
  • 1
  • 3
0
votes
0 answers

Does bash think this argument is a command?

In a bash script I have this line $var=$(printf "$otherVar" | wc -l) which is failing with the error ../test.sh: line 30: =60: command not found which I find entirely inscrutable. Presumably =60 is something it found in the contents of $otherVar,…
Charles
  • 11,269
  • 13
  • 67
  • 105
0
votes
0 answers

How to use grep function in eclipse C IDE (ubuntu)

I have a file with a couple of lines and in each one there is process id and its generation. I need to print how many processes there are in each generation and do it with only one loop and have to do it with grep and wc function but can't find how…
Roy Ancri
  • 119
  • 2
  • 14
0
votes
3 answers

wc -m seems to stop while loop in bash

I am doing an introduction course on UNIX - part of it is bash scripting. I seem to have understood the concepts, but in this particular problem I can't wrap my head around the issue. I have a txt file that consists of 1 column with random…