awk/sed script to print each line to a separate named file

I have a large 3479 line .csv file, the content of which looks likes this:

1;0;177;170;Guadeloupe;x
2;127;171;179;Antigua and Barbuda;x
3;170;144;2;Umpqua;x
4;170;126;162;Coos Bay;x
...
1205;46;2;244;Unmak Island;x
1206;47;2;248;Yunaska Island;x
1207;0;2;240;north sea;x
1208;48;2;236;atlantic ocean;x
...
3477;1;40;236;Lake Erie;x
3478;2;40;240;Lake Ontario;x
3479;3;40;244;Lake Winnipeg;x

What I need to do is print each line to a seperate unique .txt file.

The filename of each file must be in a particular format based on the contents of each line, for example "1 - Guadeloupe.txt" for the first file.

The contents of every file should be the same and is simply two lines:
trade_goods = timber
life_rating = 15

This needs to be accomplished using GNU command line tools such as sed and gawk. I am new to this.

I appreciate any help anybody can give me. Thank you.

Hi,

Try this one.

gawk 'BEGIN{FS=";";}{split($0,a,";");gsub(/ /,"",a[NF-1]); print $0 >a[NF-1];}'  input_file

Cheers,
Ranga:)

Its always good to have file names without spaces/blanks.

awk -F';' '{print "trade_goods = timber\nlife_rating = 15" > $1"-"$5".txt"}' inputfile

yes obsolutely right.

the above code will remove white spaces.

gawk 'BEGIN{FS=";";}{split($0,a,";");gsub(/ /,"",a[NF-1]); print $0 >a[NF-1];}' input_file

Cheers,
Ranga:)

# x=1;for((i=1;i<$(sed -n '$=' infile);i++)); do fname=$(sed -ne "s/^\([^;]*\).*;\([^;]*\);x/\1 - \2/;$x s/ //g" -e "$x s/.*/&.txt/p" infile); echo -e "trade_goods = timber\nlife_rating = 15">"$fname"; ((x++)); done

regards
ygemici

v="trade_goods = timber
life_rating = 15"

awk -F\; '{f=$1"-"$5; print v>f; close(f)}' v="$v" infile