Searching a particular character in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching a particular character in a file
# 1  
Old 09-23-2010
Searching a particular character in a file

Hi, I want to search how many times is "a" present in a file named "data". How to do this? Please help
# 2  
Old 09-23-2010
Code:
ruby -00 -ne 'p $_.count("a")' data

# 3  
Old 09-23-2010
Code:
times=$(awk -Fa '{print NF-1})'

or:
Code:
times=$(awk '{print gsub("a","x")})'

# 4  
Old 09-24-2010
Code:
grep -o "a" data.txt |wc -l

# 5  
Old 09-24-2010
Can convert every character in every record to a single-character record with "fold -1".
Code:
cat data | fold -1 | grep -c "a"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching invalid character in list of client name

Hi Friend, I have a client name list and client name has some invalid character due to which some issue raised and list of client are15k. I want to make script who find invalid character name. can you please help me how i can make script, i means i need logic. Valid character are :- ... (5 Replies)
Discussion started by: pallvi_mahajan
5 Replies

2. Shell Programming and Scripting

Searching Alphanumeric Character From a File

Hi, In a error log file, the error code of a particular error contains both Alphabet and Numbers. My problem statement is to find the error codes from a particular log. That means, I need to search a word, which contains both alphabet and number. Please help me. Below is two examples of error... (1 Reply)
Discussion started by: snehasish_jana
1 Replies

3. UNIX for Dummies Questions & Answers

Exclude new line character while searching

Hi, I have a log file and want to search "0.48976360737438795" with excluding new line character. Currently i am using the following command: cat LogFile.log | tr -d '\n' | grep '0.48976360737438795' This command giving me the response if file size is small but if i am using a big file... (11 Replies)
Discussion started by: ankit jain
11 Replies

4. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

5. Shell Programming and Scripting

Awk: Searching for length of words between slash character

Dear UNIX Community, I have a set of file paths like the one below: \\folder name \ folder1 \ folder2 \ folder3 \ folder4 \\folder name \ very long folder name \ even longer name I would like to find the length of the characters (including space) between the \'s. However, I want... (6 Replies)
Discussion started by: vnayak
6 Replies

6. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

7. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

8. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

9. Shell Programming and Scripting

Searching a string for a character

I have a co-worker that is trying to make a Wheel of Fortune game and he wants to know if there is a way to search a string for the letter given by the user. (7 Replies)
Discussion started by: turbulence
7 Replies

10. UNIX for Dummies Questions & Answers

searching for $ character

I need to search in text files for the $ character. I tried putting it in double quotes and single quotes . ie grep "$" filename but unix finds everything in the file. Whats the best way to do this? thanks (4 Replies)
Discussion started by: MizzGail
4 Replies
Login or Register to Ask a Question