Sponsored Content
Top Forums Shell Programming and Scripting Read line by line and store a word in array Post 302840617 by ashwin3086 on Tuesday 6th of August 2013 04:55:46 AM
Old 08-06-2013
Read line by line and store a word in array

Hi,

I would like to read a file line by line and then store the whole line word by word in array so that I can do specific manipulation on each word.


HTML Code:
 
$ cat test.txt
hello how are you
i am good

I would like to have an array created dynamically so that first time , the array will have 4 values (hello,how,are,you) and then change hello to hi and store it in the array again .Next it will have 3 values (i,am,good) and prints them.The file can have any number of lines (<1000) and each line can have upto (300 words)


Code:
 
cat newfile.txt
hi how are you
i am good


Last edited by ashwin3086; 08-06-2013 at 06:03 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Read and store each line of a file to a variable

Hi all, I'm quite new to unix and hope that someone can help me on this. I'm using csh. Below is what i intend to do. 1. I stored some data in a file. 2. I intend to read the file line by line and store each line of data into a variable, so that i can used it later. Anyone have any... (4 Replies)
Discussion started by: seijihiko
4 Replies

2. Shell Programming and Scripting

Read line by line not word by word

i have this line my,name,is,john stored in a file d.sh and i wish to print the line as string..but im getting word by word...have tried this......... for in $(cat $d.sh); do echo $i done but this is giving me my name is john (6 Replies)
Discussion started by: vadharah
6 Replies

3. UNIX for Dummies Questions & Answers

query on how to search for a line and read 4th word from that line

Assume I have a text file as below: me con pi ind ken pras ur me con rome ind kent pras urs pintu con mys ind pan pras ki con kit ind sys My requirement, I need to search for "con rome" and if exists, then print 4th word from rome, i.e in above example, since "con rome"... (4 Replies)
Discussion started by: jaggesh
4 Replies

4. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

5. Shell Programming and Scripting

Read last word of nth line

Hi people; i want to read the last word of the 14th line of my file1.txt. Here is the EXACT 14th line of the file. 250 SectorPortnum=3,AuxPortInUngo=2,PortDeviceGroup=1,PortDeviceSet=1,PorDevice=1 20 >>> Set. i have to get the word Set. how can i call it and also how... (3 Replies)
Discussion started by: gc_sw
3 Replies

6. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

7. Shell Programming and Scripting

Read last word of the line.

Hi, I need a script to read last word of the line and out put in some temp file. i it can contain any word like: My name is Harry. or My zip code is 24490 or it can be My secret code is 024H I just need last word of the line (Harry, or 2440 or 024H) Thanks for the posts below.... (10 Replies)
Discussion started by: HarryReid
10 Replies

8. Shell Programming and Scripting

Read line of files and call store procedures

Hi, I wish to write a piece of code to read lines of the flat file and cut each lines of record to a variable, then use this variable to pass as an parameter of a Sybase stored procedures, if there are 5 lines of record from the text file, then this stored procedures will be called 5 times.... (8 Replies)
Discussion started by: newbie2011
8 Replies

9. 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

10. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies
STORE(9)						   BSD Kernel Developer's Manual						  STORE(9)

NAME
store, subyte, suswintr, suword -- store data to user-space SYNOPSIS
#include <sys/types.h> #include <sys/time.h> #include <sys/systm.h> int subyte(void *base, int byte); int suword(void *base, long word); int suword16(void *base, int word); int suword32(void *base, int32_t word); int suword64(void *base, int64_t word); #include <sys/resourcevar.h> int suswintr(void *base, int word); DESCRIPTION
The store functions are designed to copy small amounts of data to user-space. The store routines provide the following functionality: subyte() Stores a byte of data to the user-space address base. suword() Stores a word of data to the user-space address base. suword16() Stores 16 bits of of data to the user-space address base. suword32() Stores 32 bits of of data to the user-space address base. suword64() Stores 64 bits of of data to the user-space address base. suswintr() Stores a short word of data to the user-space address base. This function is safe to call during an interrupt context. RETURN VALUES
The store functions return 0 on success or -1 on failure. SEE ALSO
copy(9), fetch(9) BSD
October 5, 2009 BSD
All times are GMT -4. The time now is 05:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy