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 ...
- 04-04-2008 #1Just 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.
- 04-04-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
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:
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.Code:cat <filename.txt>
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:
If you want to add the string "Whatever I say" to the end of file1.txt, you'd do:Code:cat file2.txt >> 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.Code:echo "Whatever I say" >> file1.txt
- 04-04-2008 #3
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
- 04-04-2008 #4Just 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?
- 04-04-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
There's no easy way to do what you want. Your assumption is plain incorrect, for example:
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.Roses are red,
Violets are blue,
Sugar is sweet;
And so are you
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.
- 04-04-2008 #6Just 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?
- 04-04-2008 #7
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


Reply With Quote
