Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Posts
    73

    Unanswered: column string truncation

    Hello

    I have a file with next columns:

    abscv dfghs tyhh I012453637felfwe.WAV
    cvdbb dfghs fggh I01234255363678.WAV


    could be possible using awk the truncation/spliting the fourth column in two, e.g:

    I012453637felfwe.WAV ---> I012453 637felfwe.WAV
    I01234255363678.WAV ----> I012342 55363678.WAV

    Thanks.

  2. #2
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    138
    Try this

    COLUMNS="abscf dfghs tyyh I012453637felwe.WAV"
    DUMMY=`echo $COLUMNS | awk '{
    print $1
    print $2
    print $3
    dummy1=substr($4, 1, 7)
    dummy2=substr($4, 8)
    print dummy1
    print dummy2
    }'`
    echo $DUMMY

    for i in $DUMMY
    do
    echo $i
    done

    or try this :
    here you get a new file with new columns :

    IFS="@"; for a in `cat /usr/mydir/myfile.txt`
    do
    echo $a | awk '{
    dummy1=substr($4, 1, 7)
    dummy2=substr($4, 8)
    print $1" "$2" "$3" "dummy1" "dummy2 >> "/usr/mydir/myfile.new"
    }'
    done

    Peter F.
    Last edited by fla5do; 11-29-03 at 16:42.
    Greetings from germany
    Peter F.

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    This should do it...

    awk '{print $1, $2, $3, substr($4,1,7), substr($4,8)}' yourFile > newFile

  4. #4
    Join Date
    May 2002
    Posts
    73

    Column truncation

    Thanks guys both options work pretty well.

    Regards,

Posting Permissions

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