Shell script question

Discussion in 'Computer Science & Culture' started by Jerrek, Jul 3, 2003.

Thread Status:
Not open for further replies.
  1. Jerrek Registered Senior Member

    Messages:
    1,548
    Hi, I have a fixed width file with lots of lines of text. Is there any way I can go through it, one line at a time, and copy the text from characters 11 - 27, 43 - 48, and 51 - 52 and write it to a separate text file as a concatenated string, one line per line processed?
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. AntonK Technomage Registered Senior Member

    Messages:
    1,083
    I'm sure there is a way..I'm not sure what it is in Shell Scripting...
    why not write a quick C program to do it?

    -AntonK
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Voodoo Child Registered Senior Member

    Messages:
    1,296
    I'd use sed.

    The regular expression you might use is:

    .\{10\}\(.\{17\}\).\{15\}\(.\{5\}\).\{3\}\(.\{2\}\)/\1\2\3/

    With sed:

    sed -e 's/.\{10\}\(.\{17\}\).\{15\}\(.\{5\}\).\{3\}\(.\{2\}\)/\1\2\3/ in >out

    Where in is the read from file and out is the written to file. There almost certainly a theoretical chance I remembered the syntax right.
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. Specialist Registered Senior Member

    Messages:
    46
    You could also try:
    Code:
    cut -c11-27,43-48,51-52 "<"inFile ">"outFile
    
    Without the quotes.
     
Thread Status:
Not open for further replies.

Share This Page