Unix Script file to Append Characters before rows in file.

Hi Experts,

I am working on HP-UX. I am new to shell scripting. I would like to have a shell script which will prefix:

  1. "H|" before first row of my file and,
  2. "T" for all other rows of the file.

For Example - File before running the script

20100430|4123451810|218.50|TC
20100430    $150.00	INDIA	  1234567	2      3456789
20100430    $150.00	INDIA	  1234567	2      3456789
20100430    $150.00	INDIA	  1234567	2      3456789
20100430    $150.00	INDIA	  1234567	2      3456789

File After Running the script

H|20100430|4123451810|218.50|TC
T20100430 $150.00 INDIA 1234567 2 3456789
T20100430 $150.00 INDIA 1234567 2 3456789
T20100430 $150.00 INDIA 1234567 2 3456789
T20100430 $150.00 INDIA 1234567 2 3456789

Thanks in Advance,
Phani Akella.

Hi
Try this:

awk '{if (NR==1) print "H|"$0; else print "T"$0;}' file

Guru.

awk '{$0=((NR-1)?"T":"H|")$0}1' file
sed '1s/^/H|/; 2,$s//T/' file

Regards,
Alister

using Perl:

perl -pi -e 'if ($. == 1) { s/^/H/; } else { s/^/T/; }' file.txt