Results 1 to 7 of 7

Thread: SED or AWK to cut data between certain characters from a file

  1. #1
    Join Date
    Nov 2010
    Posts
    47

    SED or AWK to cut data between certain characters from a file

    I think I am at the right place. I am up to a task and I really need help from the experts. Please help me out guys. I really do not want to put myself in a basket full of troubles. I actually want to develop a .ksh script. I want it to cut certain data from the document so that I can have the desired thing for me. It is really an important thing for me and I will be happy to see more response from you all. Any help in this matter will be appreciated and please guys I am requesting you to make the things a lot quicker. I have heard the SED and the AWK but I am not sure how can I have that for me. Any light on the two commands will also be helpful. Please make it as fast as possible.

  2. #2
    Join Date
    Nov 2009
    Posts
    865

    Re: SED or AWK to cut data between certain characters from a file

    Welcome to the forum. We will definitely try to help you all out with the problems of yours. But the thing is that the amount of information that you have presented here is not that adequate for us to tackle the situation of yours. I think that you will have to make your post again. Well you have not mentioned what you actually want to have in for you and hence I think that if you will specify the same then we will try to get the solution for you. As a suggestion by looking at the first post of yours I will ask you to try the grep. Well if at all you want to have some thing really helpful then you can revise your post. I have suggested the grep by looking that you want to cut certain data from the document.

  3. #3
    Join Date
    May 2008
    Posts
    2,680

    Re: SED or AWK to cut data between certain characters from a file

    You had asked about the SED then I think that here it is that can clear the idea behind the SED command. If you would ask me if Linux has the Search and Replace feature then I would say that it is the SED command. This command can be used to revolutionize all occurrences of one string to another that are present within a single file. It is just like the search-and-replace feature that is possessed by the word processor. Also for deleting the range of lines from a file the SED command can be brought into play. The syntax for the SED command is as follows:
    If you want to have the Substitution then
    Code:
    sed 's/<oldstring>/<newstri ng>/g' <file>
    If you want to have the file deleted then
    Code:
    sed '<start>,<end>d' < file>
    As an example if you want you can replace the word lamb with the word sheep in the file Marry.txt using the SED command as follows: sed 's/lamb/sheep/g' Marry.txt.If the file Marry.txt was having the content like: Mary had a little lamb then after executing the command it will change to: Mary had a little sheep. Hope that you would have understood the SED command and the use of the same.

  4. #4
    Join Date
    Apr 2009
    Posts
    1,107

    Re: SED or AWK to cut data between certain characters from a file

    Well I think that you will also need help on the grep command and hence I have come here with the help on the grep. I will show you how you can use the grep command so that you can have the thing done for you. grep command is actually the command for the Linux. It looks for the given file that have been asked to search or it searches for the lines in the files that contain a perfect match to the given strings or words. Once the match is found then grep starts to print those matching lines. The syntax for the grep is as follows:
    Code:
    grep 'word' filename
    grep 'string1 string2'  filename
    cat otherfile | grep 'something'
    command | grep 'something'
    If you want to search for a file using grep then you will have to type the following command:
    Code:
    $ grep boo /etc/passwd
    Where boo is the required string.
    If at you want to search for a word then the command is:
    Code:
    $ grep -w "boo" /path/to/file
    where again boo is the required sting and in addition to that it will also search for fooboo, boo123, etc. in that file.

  5. #5
    Join Date
    Nov 2010
    Posts
    47

    Re: SED or AWK to cut data between certain characters from a file

    Thanks a lot for the explanation and the suggestions that you all have given. Well in addition to that I would like to have the third one also in my favor and I will be really happy to have the explanation on the same. Well I do not think that I have not given the adequate detail of the things that I want. I made the things pretty clear and I will be happy if you all can come up with more solutions. In addition to all that I have made use of the following command:
    Code:
    sed 's/^[ \t]*//' Statement.xml | awk '/objectName|fieldValue|fieldName/' | less
    and that helped me on aligning all the information to the left. Well that is fine now I want to know if there is a script that can ask the user what file they wish to open.

  6. #6
    Join Date
    Nov 2009
    Posts
    1,035

    Re: SED or AWK to cut data between certain characters from a file

    I would say that the awk command is actuall the combination of the grep and sed. It possesses the functions of both grep and sed. Hence one can say that it is one of the most powerful commands of UNIX. Using awk, one can surrogate words from an input file's lines for words in form of a template or in addition to that can carry out calculations on numbers that are present inside a particular file. In order to use the awk command a miniature program like in C has to be written. The program will help you convert each line of the input file. The general form of the awk command is:
    Code:
    awk <pattern> '{print <stuff>}' <file>
    where stuff is some combination of text. Hope that you will find this useful.

  7. #7
    Join Date
    Nov 2010
    Posts
    75

    Re: SED or AWK to cut data between certain characters from a file

    Thanks a lot to all the members. I have really got all the explanation that I was requiring and now I am really content with all the explanations. Well I was requiring the third one i.e. awk and I think I have received the same. Now I am sure that I will be able to get what actually I wanted. Well I will try all the options that you all have suggested and will see what works in my favor. Well if I will have the problem regarding my query then I will return again.

Similar Threads

  1. Replies: 4
    Last Post: 21-02-2012, 06:14 PM
  2. Replies: 6
    Last Post: 07-07-2011, 10:23 PM
  3. Replies: 5
    Last Post: 23-12-2010, 07:12 PM
  4. Replies: 5
    Last Post: 12-08-2010, 11:36 PM
  5. Reading file with special characters
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 22-01-2010, 12:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,895,601.90610 seconds with 17 queries