Hi,
I want to do file format using awk script, for that i wan to use 'tail'. Here is the scenario. I will be having set of files in a directory. Those files i need to write to another directory with same file name, but while writing the file to out directory, i need to write the last line as first line and the rest will follow in the same order. For example, the file has below content
one
two
three
four
The file with the same name in output directory should be like
four
one
two
three
I tried like below, but wasn't working
BEGIN {
while ( ( "ls -l "ARGV[1] | getline line ) > 0 )
{
n = split(line, fileName, " ")
if (fileName[n] > 0)
{
count=0
while ((getline < (ARGV[1] "/" fileName[n]))>0)
{
dLine = $0
if (count == 0)
{
#temp = `$(tail -1 $(ARGV[1] "/" fileName[n]))`
sed -ne 1 $ARGV[1] "/" fileName[n] > ARGV[2] "/" fileName[n]
printf "\n" >> ARGV[2] "/" fileName[n]
printf dLine >> ARGV[2] "/" fileName[n]
printf "\n" >> ARGV[2] "/" fileName[n]
}
if (count != 0 && substr(dLine ,1,1) != "H")
{
printf dLine >> ARGV[2] "/" fileName[n]
printf "\n" >> ARGV[2] "/" fileName[n]
}
count = count+1
};
}
}
}
Venkata Madhu