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
0 answers

Implement the functionality of the wc and head controls

I need help to solve these requirements: Implement the functionality of the wc and head controls. The wc command will need to use and recognize the -w and -c options. The head command will need to use and recognize the -c and -n options. The…
0
votes
1 answer

Move files having only 2 lines in AIX

I have a list of files and I want to move to another directory those that contain only two lines. Is there a way to do it in a single command? I am on AIX 7.1.
Labolab
  • 3
  • 2
0
votes
1 answer

Count number of distinct folders in find result

I am running a process producing arbitrary number of files in an arbitrary number of sub-folders. I am interested in the number of distinct sub-folders and currently am trying to solve this with bash and find (I do not want to use a scripting…
Tyreal
  • 463
  • 3
  • 7
0
votes
1 answer

SAP B1 Service Layer slow performance

I have been developing an application in MVC for SAP with DI API for a month, but due to administrative decisions the client will hire a cloud service, which only allows me to use "Service Layer". The last two weeks I have been transferring…
0
votes
1 answer

why the num is wrong when I use bash -x

When I count process's number to use wc -l , The number is 2 in the command line, but I found it is 4 in the shell scripts, what's happened? $ ps -ef |grep -v grep |grep etcd |wc -l 2 $ bash -x count.sh etcd ++ ps -ef ++ grep -v grep ++ grep…
0
votes
1 answer

How to write the quantity of lines in a file to a line in a seperate file using bash

I want to count the number of lines in one file, and then overwrite a number in a second file with the number of lines. E.g. file1.txt Apples Oranges Bananas file2.txt num_lines_in_file_1 = 100 So I need to replace 100 with…
0
votes
1 answer

How to calculate number of subdirectories and byte count per file in Bash

Can I get help fixing my code to count every subdirectory (excluding "PATH" itself)? num_directories=$( find $dir -type d | wc -l) Also need help fixing the total byte count of each file total_size=$( find $dir -type f -ls | awk…
user10516592
0
votes
2 answers

How to insert word count as a string in a file?

I am trying to insert a line at the beginning of a file named text.txt that tells how many lines were in the text. Like: 35764 43587 12905 13944 After using the command, it should redirect the file into a textwc.txt,…
0
votes
1 answer

c count lines in a file avoid EOF

On numerous sources, you can find a simple C program to count the number of lines in a file. I'm using one of these. #include int main(int argc, char* argv[]) { FILE *file; long count_lines = 0; char chr; file =…
dizcza
  • 630
  • 1
  • 7
  • 19
0
votes
0 answers

bash populating number of variables

I have a text file. Using wc -l I can determine their are 15 lines. I am trying to create a number of variables based on the output of wc -l. So if I get 15 lines, I want 15 variables named var1 var2 and so on. Does anyone know a way to do this?…
Xenon
  • 171
  • 2
  • 9
0
votes
2 answers

extracting last n percentage of a file output from zcat command

I am trying to extract the last 2 percentage of a file output coming from the zcat command. I tried something doing numlines=$(zcat file.tar.gz | wc -l) zcat file.tar.gz | tail -n + $numlines*(98/100) But the problem with this approach is my file…
Pujan Paudel
  • 71
  • 1
  • 7
0
votes
2 answers

How to get file size in byte using wc -c

when I use the command to get the file size in bye using wc -c the command return two values, the size in byte and the file name, ex: the output for wc -c my_file is 322 my_file I need to get only the first value to use it if condition, and I need…
M. Edna
  • 5
  • 3
0
votes
1 answer

Issue Getting File Size with Shell Script

I have a simple shell script that reads a log of files I've uploaded, and I want to output the file size and line count (less one for the CSV header). I'm looping correctly, but when I try to use find, wc, or stat to get the size of the file it…
Jesse
  • 7
  • 1
  • 5
0
votes
1 answer

using two buffers in C program that replicates the wc command

I have the following code that simulate the wc command from linux. I need to use a buffer with the dimension of 4096 but for some reason when I execute this code i get the following result: 0 0 0 wcfile I get 0 lines, words and bytes even if the…
gameloverr
  • 53
  • 1
  • 8
0
votes
1 answer

implementation of wc command from shell in C language

I have the following code that reproduce the functionality of wc command in shell but i have some problems with the way that my code is displaying the lines, words and bytes. There is a problem with the spaces between first and second and between…
gameloverr
  • 53
  • 1
  • 8