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

wc in background does not return

In what scenario will a wc -l in bg not return? And the case below in particular I have a snippet similar to the one below in a shell script, file_name=my_file_name.xyz In one loop, wc -l ${file_name} & bg_pid=$! In another loop, wait ${bg_pid} I…
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59
0
votes
1 answer

Counting lines with specific criteria unix

I have a database with 7 columns (file.txt). I have a list with names (names.txt). I want to count the lines in file.txt where a name from names.txt appears both in column 3 and 4. Said in another way, I don't want to count the lines where the name…
0
votes
5 answers

How to use sed and wc command to handle whitespace

If I have a CSV file and I want to know the number of columns, I'll use the following command: head -1 CSVFile.csv | sed 's/,/\t/g' | wc -w However, whenever each column has a column name with a space in it, the command doesn't work and gives me…
user2763361
  • 3,789
  • 11
  • 45
  • 81
0
votes
1 answer

Store value returned by background process [not exit status]

I am counting the no. of lines in a file as a background process (I need parallel execution) counting="wc -l < abc.xyz" & `$counting` counting_process_id=$! wait $counting_process_id echo $counting This just returns a blank for $counting When I…
Suvarna Pattayil
  • 5,136
  • 5
  • 32
  • 59
0
votes
1 answer

Unix - Scripts that compares files generated by a script - check if those files have the same number of records

I have a perl script who takes files from the following path: /home/ict/extract and when i run this perl script -> this perl script has 3 options, if i choose all these 3 options, this script will create 3 files - if i choose 2 options it will…
0
votes
1 answer

print in awk is removing the spaces while printing

I am trying to print the values with awk , but it is modifying the result by removing the spaces in between fields. I am not getting how to maintain the spaces between fields. echo "First Names City Names ES"|awk '{$1=$2=$NF="";print…
Learner
  • 1,544
  • 8
  • 29
  • 55
0
votes
1 answer

Counting characters in a shell script using WC

I am writing a shell script command which counts the characters typed. I am using wc. My script is echo $1 | wc -c. The problem is that it is counting a +1 character. For example, if i type 'hello' it displays (6) characters typed but it should…
0
votes
3 answers

Find the longest sublist

I have a file containing list and sublist and I want to extract the longest sublist using command line tools. File example: * Item1 ** SubItem1 ** ... ** SubItemN * Item2 ** SubItem1 ** ... ** SubItemN * ... ** ... * ItemN ** SubItem1 ** ... **…
JohnJohnGa
  • 15,446
  • 19
  • 62
  • 87
0
votes
1 answer

Unix script to count line between pattern of output

I am trying to write a unix code where I will be to count no of rows between (ie here 2) two "|DATE and TIME | XXXXXX |" Is there any method I can use with combination of egrap and wc -l Output: |-------------------------------| |DATE and…
Sree
  • 399
  • 2
  • 5
  • 12
0
votes
1 answer

assinging `grep "string"|wc -l` into a variable in batch scripting

I am trying to develop a batch equivalent (windows) code of below unix script:- i=`grep "ora-error" *.txt|wc -l` if [ i -gt 0 ]; then echo "true" else echo "false" fi tried with "find /c "ora-error" *.txt" but was not able to take the o/p in to…
Sree
  • 399
  • 2
  • 5
  • 12
0
votes
1 answer

Count number of entries in multiple files with different name

I have say file A.txt, B.txt, C.text in a folder. Each of the text file contain few entries. How to count how many entries in each text file has? and also want to extract to a list with first column as name of text file and second column as no. of…
Ank
  • 51
  • 2
  • 6
0
votes
4 answers

File name printed twice when using wc

For printing number of lines in all ".txt" files of current folder, I am using following script: for f in *.txt; do l="$(wc -l "$f")"; echo "$f" has "$l" lines; done But in output I am getting: lol.txt has 2 lol.txt lines Why is lol.txt printed…
buch11
  • 872
  • 3
  • 13
  • 29
0
votes
1 answer

How do I list files in a folder showing name, time and number of rows in a line with bash?

How do I merge ls with wc -l to get the name of a file, modification time and number of rows in a file? thanks!
user1171632
  • 870
  • 1
  • 8
  • 9
-1
votes
1 answer

wc command with no FILE argument (reading from standard input)

Regarding 'wc' (word count) command... I am trying to understand the following (from 'man wc' which I have quoted below) "With no FILE, or when FILE is -, read standard input." How exactly does this work? At what point do I type the "standard…
PurpleMongrel
  • 112
  • 1
  • 9
-1
votes
2 answers

wc command ignore if column have multiple lines

I am trying to get lines count of csv file using wc command wc -l test.csv But, this command giving me incorrect count since one the column have multiple rows in csv file. test.csv format: column1 column2 column3 hi hello hi …
Sanjay Chintha
  • 326
  • 1
  • 4
  • 21