How can I read complete word from text file?


 
Thread Tools Search this Thread
Top Forums Programming How can I read complete word from text file?
# 1  
Old 12-09-2012
How can I read complete word from text file?

how can I know that the word in test file end at this point .... I have an Idea to search on ' ' , '\n' or '\0' but don't know what function can store the string before those characters ..

help please !
# 2  
Old 12-09-2012
If you want to obtain the last field/word per line in a space delimited file, try this:

Code:
 
awk '{ print $NF }'  file

# 3  
Old 12-10-2012
not only last word........ every word
# 4  
Old 12-10-2012
Code:
awk ' { for(word=1;word<=NF;word++) print $word } ' input_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C Code to read a word from file

Hello All, I have to write a C Code to read a word from file and Keep track of the number of word occurrence in each line and total in the file. Maintaining total count is easier but maintaining per line count is what I am struggling to achieve. I thought of maintaining linked list... (3 Replies)
Discussion started by: anand.shah
3 Replies

2. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

3. Shell Programming and Scripting

How to read nth word from delimited text file?

Hi i am new in scripting how i can get 2 elements from first line of delimited txt file in shell scripts. AA~101010~0~AB~8000~ABC0~ BB~101011~0~BC~8000~ABC~ CC~101012~0~CD~8000~ABC0~ DD~101013~0~AB~8000~ABC~ AA~101014~0~BC~8000~ABC0~ CC~101015~0~CD~8000~ABC~ can anyone plse help?... (3 Replies)
Discussion started by: sushine11
3 Replies

4. UNIX for Dummies Questions & Answers

how to read the second word of a text file

Folks, how to read the second word of the first line from a text file. Text file does not have any delimiters in the line and has words at random locations. Basically the text file is a log and i want to capture a number that is in second position. Appreciate your help Venu (1 Reply)
Discussion started by: venu
1 Replies

5. UNIX for Dummies Questions & Answers

How to get complete path in variable excluding last word?

Hello Experts, Can you please help me by providing a code which can give me the complete path except last word in a variable, the variable i can use anywhere else for my operation eg: if this below one is my path: ... (3 Replies)
Discussion started by: aks_1902
3 Replies

6. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

7. UNIX for Dummies Questions & Answers

Read last word of file name

Hi I am writing a script that needs to read all file from a directory and print only last word of all file names. My script: for file in /documents/files/ do $shortFile=$(file##.*) echo $shortFile done All my file names in /document/files/ directory are like unix_ubuntu but I need to... (1 Reply)
Discussion started by: watsup
1 Replies

8. UNIX for Advanced & Expert Users

Delete a word and complete line

Hi Canone please provide me solution how can achieve the result below: File1.txt $ sweet appleŁ1 scotish green $ This is a test1 $ sweet mangoŁ2 asia yellow $ This is a test 2 $ sweet apple red (there is no pound symbol here) germany green (1 Reply)
Discussion started by: Aejaz
1 Replies

9. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

10. Shell Programming and Scripting

how to read each word in a file

Hi, I want to read each word in a file. start at a particular character say '%' and read till another character say ')' (these two characters form the part of my file). then i want to delete the whole sentence(that is between '%' and ')' ) and keep the remaining file intact. Its urgent... (1 Reply)
Discussion started by: kaps_jhaver
1 Replies
Login or Register to Ask a Question