Find text in file

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find text in file
# 1  
Old 12-23-2013
Find text in file

Hello i a script:

for iname in `cat mysong`
  for cname in `cat mysong`
    if  [ "$iname" = $cname ]
       count=`expr $count + 1`
    echo "word: $iname - found in the text: $count times" 

the proplem: how i can print not duplicated words. (i can't use sort and unic )

my output:
word: I - found in the text: 8 times
word: I - found in the text: 8 times

Thank you
# 2  
Old 12-23-2013
Is this homework assignment?
# 3  
Old 12-23-2013
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and replace a string in a text file

Dear all, I want to find all the "," in my text file and then replace the commas to a tab. I found a script online but I don't know how to modify the script for my case. Any one can help? Thank you. @echo off &setlocal set "search=%1" set "replace=%2" set "textfile=Input.txt" set... (2 Replies)
Discussion started by: forevertl
2 Replies

2. Shell Programming and Scripting

How to find numbers in text file?

Hi I have a text file with rows like this: 7 Herman ASI-40 Jungle (L) Blueprint (L) Weapon Herman ASI-40 Jungle (L) 215.00 57 65.21 114.41 and 9 Herman CAP-505 (L) Blueprint (L) Weapon Herman CAP-505 (L) 220.00 46.84 49.1 104.82 and 2 ClericDagger 1C blueprint Melee - Shortblade... (2 Replies)
Discussion started by: pesa
2 Replies

3. UNIX for Advanced & Expert Users

Find and replace the line in text file

I have two files a.txt b.txt I want to find a line in a.txt and replace by another line from b.txt a.txt asfsdfsfsfdfsf asfwererfgdgf wrerwetretfdg b.txt werdfgdfgf werergfdgd sfdfgfgfgfgg i want to replace the 1st line of a.txt by 1st line of b.txt i want out put as (5 Replies)
Discussion started by: rammm
5 Replies

4. Shell Programming and Scripting

find from file and replace with specific text

Dear All, I do not have any knowledge of scripting. I want to replace specific lines of a text file with a specific text. Like I have one file which is "original file" and one file "changes file" which has list of lines which I want to replace in original file with a specific string. I want the... (5 Replies)
Discussion started by: libras
5 Replies

5. Shell Programming and Scripting

Find redundant text in a file

I want to find which pattern or strings have occurred more than one time so that I can remove unnecessary redundancy. For example: If I have the sentence: A quick brown brown fox jumps jumps jumps over the lazy dog in a file, then I want to know that 1. the word "brown" has... (7 Replies)
Discussion started by: hbar
7 Replies

6. Shell Programming and Scripting

Find string in text file

Hello! Please, help me to write such script. I have some text file with name filename.txt I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable. For... (3 Replies)
Discussion started by: optik77
3 Replies

7. Shell Programming and Scripting

Find ^Z in a unix text file

Hi Everybody, I have an unknown number of files that for some reason contain the ^Z character. I would need a command that helps me identifying these files. Here is an example of a line: JUAN HERN^ZNDEZ I would greatly appreciate your help. Thanks in advance, Sebastian (3 Replies)
Discussion started by: hhoosscchhii
3 Replies

8. Shell Programming and Scripting

find a string in a file and add some text after that file

Hi Could you please help me out by solving teh below problem ? I have a file with as below source1|target1|yes source2|target2|no source1 is file in which i have to place some code under the <head> tag in it. What code i have to place in source1 is something like this "abcd.....<target1>... (5 Replies)
Discussion started by: Tasha_T
5 Replies

9. UNIX for Dummies Questions & Answers

How to find exact text in file ?

I have file named shortlist , and it contains this: 2233|charles harris |g.m. |sales |12/12/52| 90000 9876|bill johnson |director |production|03/12/50|130000 5678|robert dylan |d.g.m. |marketing |04/19/43| 85000 2365|john woodcock |director |personnel... (1 Reply)
Discussion started by: Cecko
1 Replies

10. Shell Programming and Scripting

How to find Duplicate Records in a text file

Hi all pls help me by providing soln for my problem I'm having a text file which contains duplicate records . Example: abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 tas 3420 3562 ... (1 Reply)
Discussion started by: G.Aavudai
1 Replies
Login or Register to Ask a Question