Find the answer to your Linux question:
Results 1 to 4 of 4
Hello friends. i have a question about using awk. for example there is a document & there are lots of xyz word in the document. how can i count this ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    1

    awk question

    Hello friends.
    i have a question about using awk.
    for example there is a document & there are lots of xyz word in the document.
    how can i count this xyz.
    i want to show there are ... xyz word in this document.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Try this..

    usage:

    awk -f prog.awk filename

    Code:
    #! /usr/bin/awk -f
    
    BEGIN	{
    		print("Searching for the xyz....\n");
    		found = 0;
    		lines = 0;
    		FS = "";
    	}
    
    {	++lines;
    	for (i = 1; i <= NF; ++i)
    	{
    		++charin;
    		
    		if (($i == "x") && ($(i + 1) == "y") && ($(i + 2) == "z"))
    		{
    			++found;
    			printf("found entry %d, on line %d\n", found, lines);
    		}
    	}
    }
    
    END	{
    		printf("found %d entries...\n", found);
    	}
    Make mine Arch Linux

  3. #3
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    awk ' {m=gsub(/xyz/,"") ;t+=m} END{print t}'  file

  4. #4
    Just Joined!
    Join Date
    Dec 2009
    Posts
    1

    Smile Compare two text files

    Hai guys i have one question

    i have two files

    cat > file1

    9842121,a4
    9942121,a4
    9742121,a4

    cat > file2
    9842121,a4
    9742121,a4
    9442121,a4


    iwant output like below

    9842121,a4

    basicallly i wnat to compare two text files first column and if it is same the i would print it in a new text file

    can anybody help me out please

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...