Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
Hello everyone ! here is a problem.... suppose I am having a text file containing 10 lines. Now I want to create file1 with line1 of it. Then file2 having ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2012
    Location
    Bangalore
    Posts
    22

    Creating new files each containing one line from a text file


    Hello everyone !
    here is a problem....
    suppose I am having a text file containing 10 lines. Now I want to create file1 with line1 of it. Then file2 having line2 of text file and so on

    Also while giving solution, if you explained it a little, it'll be more helpful since I am new to scripting.

  2. #2
    Linux Newbie
    Join Date
    Sep 2012
    Posts
    148
    Can you be a little more spacific on what your trying to do??

  3. #3
    Just Joined!
    Join Date
    Sep 2012
    Location
    Bangalore
    Posts
    22
    I have a text file which contains say n number of lines. Now I want to save line no 1 of my text file into new file(say <file1>), then line no 2 of my text file in again new file <file2>. I want to repeat this till last line of my text file (n) and the last file created will be <filen>
    So, basically I want to derive multiple files sequentially saving particular line of my text file.
    I hope this explains the problem definition.

  4. #4
    Linux Newbie
    Join Date
    Sep 2012
    Posts
    148
    So your wanting to save each line of your text file into a seperate file?

  5. #5
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    I'm not much of a coder, but if you post a snippet of what you've tried, it may help others point you in the right direction.
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  6. #6
    Just Joined!
    Join Date
    Sep 2012
    Location
    Bangalore
    Posts
    22
    Quote Originally Posted by awesomepilot View Post
    So your wanting to save each line of your text file into a seperate file?
    Yes this is what I want.

  7. #7
    Just Joined!
    Join Date
    Sep 2012
    Location
    Bangalore
    Posts
    22
    Quote Originally Posted by jayd512 View Post
    I'm not much of a coder, but if you post a snippet of what you've tried, it may help others point you in the right direction.
    I will definitely do that after completion !

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    Quote Originally Posted by Shantanu View Post
    I will definitely do that after completion !
    i think Jay means before completion! so we can see what you've tried...

  9. #9
    Just Joined!
    Join Date
    Sep 2012
    Location
    Bangalore
    Posts
    22
    I haven't tried anything yet ! I am hoping to get a idea to write a bash script for given problem statement !
    I am new to bash scripting so I am unable to post anything beforehand

  10. #10
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    43
    This sounds a little bit like a homework, which is forbidden by the forum. Nevertheless, try using a while loop piping a cat of your file to it, that should do the trick.

Page 1 of 2 1 2 LastLast

Posting Permissions

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