Find the answer to your Linux question:
Results 1 to 2 of 2
Hi I have a requirement like this: Cut the characters from each line of a file with following positions: 21-24, 25-34 ,111-120. These fields now need to be placed in ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    1

    Post Pasting multiple cut outputs to a tab delimited output file


    Hi
    I have a requirement like this:
    Cut the characters from each line of a file with following positions:
    21-24, 25-34 ,111-120.
    These fields now need to be placed in a tab delimited output file.
    Currently this is how I am achieving it:
    #!/bin/sh
    cat newsmaple.txt | cut -c 21-24 > out1.txt
    cat newsmaple.txt | cut -c 25-34 >out2.txt
    cat newsmaple.txt | cut -c 111-120 >out3.txt
    paste out1.txt out2.txt out3.txt >out.txt
    rm out1.txt out2.txt out3.txt
    cat out.txt

    It does produce the required output but the code does not look clean. Is there a better way of doing this. Also I wish to avoid the 3 temporary outputfiles:
    out1.txt out2.txt out3.txt .
    Could you please help me on this.

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    478
    welcome to the forum

    something like this might work

    cut --output-delimiter="\t" -c 21-24,25-34,111-120 <newsmaple.txt >out.txt
    the sun is new every day (heraclitus)

Posting Permissions

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