Assistance Required - manipulating records

Hi guys, I need to do a bit of work to a file.

Basically I want to run a SQL statement against each record in this file (hundreds of lines):

sample input:

233333
233334
233335
233336

I want to do the following:

  1. Add a some text at the beginning to prepare the SQL (3 lines)
  2. Add some text at the end for cleanup (4 lines)
  3. Remove whitespace at the end - SORTED sed 's/[ \t]*$//' - seems to leave 2 spaces?!!??!)
  4. Add a letter 'a'to the end - SORTED (awk 'print $0 "a"})
  5. Now the complicated part, I want to take the number above and make it look like the sample output below. The same for each line.....!?
COPY BATCH_233333a INTO /dir/dir/dir/BATCH_233333a.txt
COPY BATCH_233334a INTO /dir/dir/dir/BATCH_233334a.txt
COPY BATCH_233335a INTO /dir/dir/dir/BATCH_233335a.txt
COPY BATCH_233336a INTO /dir/dir/dir/BATCH_233336a.txt

Any help is appreciated

sed 's#.*#COPY BATCH_&a /dir/dir/dir/BATCH_&a.txt#' myFile

its official i love you

Thanks, anyn thoughts as to why the following awk doesn't add the "a" directly to the end of the line but instead adds it like:

input

9315
9602
9604
9734
9746
9750
9753
9315  a
9602  a
9604  a
9734  a
9746  a
9750  a
9753  a

awk 'print $0 "a"}

Probably you have spaces in your input file!
Try:

sed 's# ##g' <inFile>

Or better:

sed 's#[ \t]##g' <inFile>
1 Like

probably 'cause it's syntactically incorrect statement...

awk '{print $0 "a"}' myFile
1 Like

edit - please wait - I am producing a new input file.

syntax was ok in awk - typo here on this site

awk '{printf "COPY BATCH_%sa INTO /dir/dir/dir/BATCH_%sa.txt\n", $1,$1}' infile
1 Like

thanks - you may close

I appreciate everyone's help.