Find the answer to your Linux question:
Results 1 to 7 of 7
I am using secure shell and i am very new to this. I just have a couple of questions. The first one is that i have a file and this ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4

    newbie questions

    I am using secure shell and i am very new to this. I just have a couple of questions. The first one is that i have a file and this file has names in it. I need to print these names to the screen. My second question is i need to insert extra lines into a text file. Any information on how to do these would be great. I think with the first question i need to use the linux menu command but i am not sure.

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by nick2price View Post
    I am using secure shell and i am very new to this. I just have a couple of questions. The first one is that i have a file and this file has names in it. I need to print these names to the screen. My second question is i need to insert extra lines into a text file. Any information on how to do these would be great. I think with the first question i need to use the linux menu command but i am not sure.
    It's hard to guess what you intend to do.

    To see the contents of a file from the shell (in a terminal or being logged in text mode) you use the "cat" command. For example:

    Code:
    cat <filename.txt>
    The file name doesn't neet to have the .txt extension, but it *must* be a text file. Cat doesn't support binary files. Only plain text.

    If you wan't anything more elaborated, you must give more info on what you want to do.

    To insert more lines *at the end of the file*, you can use the reddirection operator, in conjunction with echo, or cat. For example, if you want to add the contents of file2.txt to file1.txt, you'd do:

    Code:
    cat file2.txt >> file1.txt
    If you want to add the string "Whatever I say" to the end of file1.txt, you'd do:

    Code:
    echo "Whatever I say" >> file1.txt
    If you need something more advanced, then you must look into the sed and awk commands. Or code something in perl or python.

  3. #3
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    I would suggest you to check linuxcommand.org too.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  4. #4
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4
    The file has written sentences in it but i just need to search the words that are names and print them out. The question was given to me as:
    List of proper names appearing in the text (In English they appear with a capital letter - but so does the first word of the sentence!).
    If i am right, Sentences should not start with a name as that is bad English, so how would i print all the words in a file that start with a capital letter but do not come after a fullstop?

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by nick2price View Post
    The file has written sentences in it but i just need to search the words that are names and print them out. The question was given to me as:
    List of proper names appearing in the text (In English they appear with a capital letter - but so does the first word of the sentence!).
    If i am right, Sentences should not start with a name as that is bad English, so how would i print all the words in a file that start with a capital letter but do not come after a fullstop?
    There's no easy way to do what you want. Your assumption is plain incorrect, for example:

    Roses are red,
    Violets are blue,
    Sugar is sweet;
    And so are you
    Three of those four verses start with a name. You can change "roses", "violets" and "sugar" by "john", "claire" and "rambo" if you want. That's correct and perfectly possible.

    If you still want to do it that way, the best bet is awk as I told you above. So, read on awk.

    But the only correct way I can think of would be a dictionary based search. But there's no way you can cataloge all the names into a dictionary file...

    The "right" way to do it would involve parsing the grammar, some IA and heuristics, and a semantical analysis as well if you only want proper names but not common ones.

  6. #6
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4
    kool, i am understanding the awk command, but how do i set it to print out only names with capital letters? Or even to start of with, how do i get it to print out all words with capital letters?

  7. #7
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Regular expressions.

    Something like: [A-Z]*
    But you'll need to modify that to your purpose. One problem with this is (as always) human error. Can you be 100% sure that the file has consequently written all names with a capital? If I had a penny for every mistake I saw in capitalization... *sigh*


    Another approach is to make a list of all the names. This is doable if you know which names you're looking for. Like, all the names of your co-workers. Then compare the list you've made with the file you're examining.
    Can't tell an OS by it's GUI

Posting Permissions

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