Deleting the garbage character from a file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Deleting the garbage character from a file

  1. #1
    Join Date
    Mar 2007
    Posts
    167

    Deleting the garbage character from a file

    Hi,

    I am having a flat file having comma separated values. The first two characters of the first field is some garbage . I want to delete those two characters from the field.

    sample data : - 1236934822~175

    i want only 1236934822

    I am using linux shellscript to do this
    Code:
    Data=`cat "${FILE_PATH}/${FILE_NAME}" |head -1| cut -d~ -f1`
    Actual_Data=`echo | awk '{ print substr("'"$Data"'",3) }'`
    its giving me only 1.

    Also i want to replace the value 1236934822 with 1236934822 in the roiginal file for further processing.


    Can anyone help me on this.

    I dont know the actual forum to put this question so i put it here. Guide me.


    Thanks
    Ashwini

  2. #2
    Join Date
    Sep 2003
    Posts
    207

    Re: Deleting the garbage character from a file

    Hi

    Is the length of each line very unpredictable? If not then maybe this can help you.

    Code:
    cat "${FILE_PATH}/${FILE_NAME}" | cut -c 3-999 > temp.txt
    mv temp.txt "${FILE_PATH}/${FILE_NAME}"
    Not very good because of the 999. Im not sure whether there is a way to get the max length of each line.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center