CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007

    Deleting the garbage character from a file


    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
    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.


  2. #2
    Join Date
    Sep 2003

    Re: Deleting the garbage character from a file


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

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)