Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2017
    Posts
    1

    Unanswered: AWK scripting - how to get back to beginning of input file

    Hi All.
    I need help with AWK file. I have first time writing it and have one problem. Please advise how i can solve it (if it possible in AWK as well).
    I have input file (csv file). I need go to last line of file, get value of second column and save it to my variable.
    After this i need to get back to begin of file and start read all lines and add my variable among fields.
    All lines goes to new output file csv.

    Here is my awk file:
    {my_var}
    {
    if ($1==1)
    {my_var=$2;}
    print($3","$5","my_var","$12);
    }

    This command i run script in unix:
    tr -d "\015" < INPUT_FILE.csv | awk -F"," -fMY_SCRIPT.awk > OUTPUT_FILE.csv

    How i can return carriage to begin of file, i.e to line 1 and read again after population my var ??
    Last edited by bandrew; 02-02-17 at 04:27.

Tags for this Thread

Posting Permissions

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