Help with a script

Lets say I have a file suffixed with a year
eg: test_file_2010.txt which has some 40 records

So now, the requirement is, Since the file has the year "2010" suffixed,

I just want to add a column say FY10 and under it everything else should be FY10 again(40 rows)

FY!0(column)
FY10
FY10
FY10......

I hope the requirement is clear...

please help.

You will have more chances of a response if you display the input and desired output.

If your columns are space delimited then:

while read r 
do
echo "FY10" $r
done < test_file_2010.txt > new_test_file_2010.txt

or else you may need to replace echo with printf and format the text.

$ awk '{print "FY10 "$0}' test_file_2010.txt
for i in *.txt
do
 year=$(echo "$i" | nawk -F. '{print substr($(NF-1),length($(NF-1))-1,length($(NF-1)))}')
 sed "s/^/"FY$year"/" $i > new_$i # if you dont want to create a new file, then use "sed -i"
done

Only Xbin's code worked fine....

Xbin: I have other files also suffixing with different years and i want to include all the files in that script..How do i go abt doing it????

Itkamaraj: Your code seemed to be more dynamic but got inappropriate results..

I would love to get some kind of code that way....where if it finds 2010,2011 or 2012 in a text file, it shud automatically put in a column with appropriate year and corresponding rows...

Appreciate all your help

but got inappropriate results

Please tell what u got when u run the code. And what is your expectation

while read r
do
echo "FY10" $r
done < test_file_2010.txt > new_test_file_2010.txt

The above code changes the input file which is a tab delimiter to space delimiter..How can i retain the Tab delimiter in the new test file

while IFS="" read r; do
    printf "FY10\t%s\n" "$r"
done

Script works perfect...Can somebody explain line by line what the script does exactly