paste a block of text horizontally

Discussion in 'Software' started by key, Jan 10, 2008.

  1. key

    key Private E-2

    i was torn between adding this in "Software" or "Programming", but i thought it might be a question geared more towards you programmers.

    anyway, i need a way to copy multiple lines of text (a rather large block of plain text), add a [space][-][space] then paste the lines again somehow.

    example:

    Code:
    this is the first line of text
    this is the second line of text
    this is the third line of text
    this is the fourth line of text
    would become

    Code:
    this is the first line of text - this is the first line of text
    this is the second line of text - this is the second line of text
    this is the third line of text - this is the third line of text
    this is the fourth line of text - this is the fourth line of text
    maybe someone knows of a trick or a script to do this?
    i've looked at a couple pieces of software (bkreplacem, text magician, and have been trying to figure this out for a long time, but i can't wrap my head around the subject.
     
  2. Wookie

    Wookie Sergeant Major

    Well if your a programmer, pretty simple to do

    Here is some java that does exactly that, you could use a writer to write it back out to a text file, write now I just send it to standard output

    Code:
    import java.io.*;
    
    
    public class copyTxt{
    
    
    	public static void main(String[] args)
    	{
    		try{
    			FileReader text = new FileReader("test.txt");
    			BufferedReader bRead = new BufferedReader(text);
    			boolean eof = false;
    
    			while(!eof)
    			{
    				String tmpString = bRead.readLine();
    				if(tmpString == null)
    					eof=true;
    				else
    					System.out.println(tmpString + " - " + tmpString);
    			}//end while
    			bRead.close();
    		
    		
    		}//end try
    		catch(IOException e)
    		{
    			System.out.println(e.toString());	
    		}
    		
    	}//end main
    
    }//end copyTxt

    Example output

    Code:
    this is the first line of text - this is the first line of text
    this is the second line of text - this is the second line of text
    this is the third line of text - this is the third line of text
    this is the fourth line of text - this is the fourth line of text
     
  3. Wookie

    Wookie Sergeant Major

    Heres an entire command line program to do it :)

    Code:
    import java.io.*;
    
    
    public class copyTxt{
    
    
    	public static void main(String[] args)
    	{
    		if (args.length == 2)
    		{
    			try{
    				FileReader text = new FileReader(args[0]);
    				FileWriter out = new FileWriter(args[1]);
    				BufferedWriter bWrite = new BufferedWriter(out);
    				BufferedReader bRead = new BufferedReader(text);
    				boolean eof = false;
    
    				while(!eof)
    				{
    					String tmpString = bRead.readLine();
    					if(tmpString == null)
    					{	eof=true;	}
    					else
    					{
    						System.out.println(tmpString + " - " + tmpString);
    						bWrite.write(tmpString + " - " + tmpString + "\n");
    					}
    				}//end while
    				bRead.close();
    				bWrite.close();
    		
    		
    			}//end try
    			catch(IOException e)
    			{
    				System.out.println(e.toString());	
    			}
    			}//end if
    			else
    			{ System.out.println("Usage: java copytext inputtextfile outputtextfile"); }
    	}//end main
    
    }//end copyTxt

    Install the java JDK, run javac copyTxt.java to compile and then run it from command line like so

    java copyTxt test.txt testout.txt

    test.txt being input and testout.txt being output, or just message me and I can send you the compiled file if you trust me.
     
  4. key

    key Private E-2

    Brilliant! works beautifully. thanks a ton Wookie, i'm in debt to ya :major
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds