LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   trim a line (http://www.linuxquestions.org/questions/programming-9/trim-a-line-370675/)

schneidz 10-07-2005 11:50 AM

trim a line
 
hi lq,

i have a line of text like:
Code:

hello my name is simon. and i like to do drawings.
i always want to trim out byte position 9 - 13 (name) and 17 - 22 (simon).

how do i do it in 'c' or bash or awk.

thanks,

Dark_Helmet 10-07-2005 12:16 PM

Ok, you want to trim "byte" positions... Is that an absolute requirement statement, or just extra description? I mean, will you want to remove byte positions 9-13 and 17-22 everytime, or were they just used to reinforce the location of "name" and "simon"?

If you want to trim those positions everytime, then you can use cut:
Code:

$ echo "hello my name is simon. and i like to do drawings." | cut -c 0-8,14-16,23-
hello my is. and i like to do drawings.

If it's word position you're after:
Code:

$ echo "hello my name is simon. and i like to do drawings." | cut -f 1,2,4,6- -d' '
hello my is. and i like to do drawings.


schneidz 10-07-2005 06:47 PM

'cut', bonne idée

thanks helmet


All times are GMT -5. The time now is 07:45 AM.