Sponsored Content
Top Forums Shell Programming and Scripting [Solved] making each word of a line to a separate line Post 302611763 by rbalaj16 on Friday 23rd of March 2012 12:02:50 PM
Old 03-23-2012
Question [Solved] making each word of a line to a separate line

Hi,

I have a line which has n number of words with separated by space.

I wanted to make each word as a separate line.

for example,

i have a file that has line like
Code:
i am a good boy



i want the output like,

Code:
i
am
a 
good
boy

Please suggest.

Last edited by radoulov; 03-23-2012 at 01:39 PM.. Reason: Code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making multi line output appear on one line

Basically I wanna take grep output, EACH_OPTION_CHARGE: V033*, VMVM, 4.00, M EACH_OPTION_CHARGE: V040*, VMVM, 4.00, M EACH_OPTION_CHARGE: V042*, VMVM, 4.50, M EACH_OPTION_CHARGE: V043*, VMVM, 5.00, M EACH_OPTION_CHARGE: V050*, VMVM, 4.00, M EACH_OPTION_CHARGE: V052*,... (1 Reply)
Discussion started by: djsal
1 Replies

2. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

3. Shell Programming and Scripting

Replace a line with a separate line in code

I have a bunch of files that are like this: <htmlstuffs>HTML STUFFS</endhtmlstuffs> <h1>Header</h1> <htmlstuffs>HTML STUFFS</endhtmlstuffs> <h1>Unique</h1> <html stuffs>HTML STUFFS</endhtmlstuffs> And Here's what I'd like it to look like: <htmlstuffs>HTML STUFFS</endhtmlstuffs>... (2 Replies)
Discussion started by: kason
2 Replies

4. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

5. Shell Programming and Scripting

Read each line and saving the line in separate files

Hi Experts, I am having a requirement like this; Input file EIM_ACCT.ifb|1001|1005 EIM_ADDR.ifb|1002|1004 EIM_ABD.ifb|1009|1007 I want to read each line of this file and pass each line,one at a time,as an argument to another script. eg; 1.read first line->store it to a file->call... (2 Replies)
Discussion started by: ashishpanchal85
2 Replies

6. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

7. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

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

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

10. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies
STRSPLIT(3pub)						       C Programmer's Manual						    STRSPLIT(3pub)

NAME
strsplit - split string into words SYNOPSIS
#include <publib.h> int strsplit(char *src, char **words, int maxw, const char *sep); DESCRIPTION
strsplit splits the src string into words separated by one or more of the characters in sep (or by whitespace characters, as specified by isspace(3), if sep is the empty string). Pointers to the words are stored in successive elements in the array pointed to by words. No more than maxw pointers are stored. The input string is modifed by replacing the separator character following a word with ''. However, if there are more than maxw words, only maxw-1 words will be returned, and the maxwth pointer in the array will point to the rest of the string. If maxw is 0, no modification is done. This can be used for counting how many words there are, e.g., so that space for the word pointer table can be allocated dynamically. strsplit splits the src string into words separated by one or more of the characters in sep (or by whitespace characters, as defined by isspace(3), if sep is the empty string). The src string is modified by replacing the separator character after each word with ''. A pointer to each word is stored into successive elements of the array words. If there are more than maxw words, a '' is stored after the first maxw-1 words only, and the words[maxw-1] will contain a pointer to the rest of the string after the word in words[maxw-2]. RETURN VALUE
strsplit returns the total number of words in the input string. EXAMPLE
Assuming that words are separated by white space, to count the number of words on a line, one might say the following. n = strsplit(line, NULL, 0, ""); To print out the fields of a colon-separated list (such as PATH, or a line from /etc/passwd or /etc/group), one might do the following. char *fields[15]; int i, n; n = strsplit(list, fields, 15, ":"); if (n > 15) n = 15; for (i = 0; i < n; ++i) printf("field %d: %s ", i, fields[i]); In real life, one would of course prefer to not restrict the number of fields, so one might either allocated the pointer table dynamically (first counting the number of words using something like the first example), or realize that since it is the original string that is being modified, one can do the following: char *fields[15]; int i, n; do { n = strsplit(list, fields, 15, ":"); if (n > 15) n = 15; for (i = 0; i < n; ++i) printf("field %d: %s ", i, fields[i]); list = field[n-1] + strlen(field[n-1]); } while (n == 15); SEE ALSO
publib(3), strtok(3) AUTHOR
The idea for this function came from C-News source code by Henry Spencer and Geoff Collyer. Their function is very similar, but this implementation is by Lars Wirzenius (lars.wirzenius@helsinki.fi) Publib C Programmer's Manual STRSPLIT(3pub)
All times are GMT -4. The time now is 02:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy