Results 1 to 6 of 6

Thread: [SOLVED] How to cut and display first 250 chars from some file?

  1. #1
    Join Date
    Jun 2006
    Beans
    Hidden!

    [SOLVED] How to cut and display first 250 chars from some file?

    example: i created one file in ~/ named text (so ~/text).
    Q: How can i cut first 250 chars from ~/text and display them in terminal using
    cut?

    tnx

  2. #2
    Join Date
    Sep 2008
    Beans
    125
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to cut and display first 250 chars from some file?

    I don't really understand your question. You want to create a program that does this? If yes you can use "fread". You can find more information here :
    http://www.cplusplus.com/reference/c...dio/fread.html
    If you want to use bash for this you can use read and then echo.
    Hope this helps.

    Best wishes,
    NoReflex

  3. #3
    Join Date
    Jul 2008
    Location
    $HOME
    Beans
    1,030
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: How to cut and display first 250 chars from some file?

    Quote Originally Posted by jakonj View Post
    example: i created one file in ~/ named text (so ~/text).
    Q: How can i cut first 250 chars from ~/text and display them in terminal using
    cut?

    tnx
    I believe that “cut” only works on lines. For multi-line files, something else will be required, perhaps “gawk”.
    If people were nicer, I'd answer more queries here!

  4. #4
    Join Date
    Sep 2006
    Beans
    2,914

    Re: How to cut and display first 250 chars from some file?

    Quote Originally Posted by jakonj View Post
    example: i created one file in ~/ named text (so ~/text).
    Q: How can i cut first 250 chars from ~/text and display them in terminal using
    cut?

    tnx
    if you want to cut 250 chars from every line
    Code:
    awk '{print substr($0,1,250)}' file
    cut -b1-250 file
    if you want to cut only the first 250 and ignore the rest of the lines
    Code:
    head -1 file | cut -b1-250
    Last edited by ghostdog74; September 19th, 2008 at 12:55 PM.

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Beans
    1,805

    Re: How to cut and display first 250 chars from some file?

    Quote Originally Posted by jakonj View Post
    example: i created one file in ~/ named text (so ~/text).
    Q: How can i cut first 250 chars from ~/text and display them in terminal using
    cut?

    tnx
    Use your head.
    Code:
    head -c 250 ~/text
    ...

  6. #6
    Join Date
    Jun 2006
    Beans
    Hidden!

    Re: How to cut and display first 250 chars from some file?

    Quote Originally Posted by mali2297 View Post
    Use your head.
    Code:
    head -c 250 ~/text
    This works. Arigato for help

Tags for this Thread

Bookmarks

Posting Permissions

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