Merge all commands into one

how can i merge follwoing process to one...

tail +5 rawdata_AAA_1.txt_$$ | grep -v "^$" >> rawdata_AAA_2.txt_$$

For discarding first 5 rows and deleting null rows

awk '!/^ /{if(a) print a; a=$0}/^ /{print a}' rawdata_AAA_2.txt >> rawdata_AAA_3.txt  

For merging record if it split into 2 rows

awk '$2 != "" {print}' rawdata_AAA_3.txt_$$ | sort | uniq  >> rawdata_AAA_4.txt_$$  

For sorting and removing duplicate data

awk '{print "AAA "$0}' rawdata_AAA_4.txt >> final_rawdata.txt

For adding column at first in the file..

How can i club all this process into one command?

Just post a sample data and an example of the desired output.

I'm not sure to understand your merge command. Seems that for lines starting with a space the command prints the last lines not starting with a space.

Please give us an example of input and output datas.

Jean-Pierre.

Below if same data in my file

Job Name                        Last Start        Last End     ST  Run  Pri/Xit
____________________________ ________________ ________________ __ _______ ___

35111_AAA         -----            -----            OI 0/0
  35111_BBB        -----            -----            IN 0/0
35111_CCC               09/01/2009 08:57 09/01/2009 08:57 FA 55556015/1 1


35111_DDD
                             -----            -----            OI 0/0

35111_EEE
                             03/20/2008 11:27 03/20/2008 11:40 SU 38917388/2
35111_FFF         -----            -----            OI 0/0


35111_GGG         -----            -----            OI 0/0

I want data in following format

AAA  35111_AAA         -----            -----            OI 0/0
AAA  35111_BBB        -----            -----            IN 0/0
AAA  35111_CCC   09/01/2009 08:57 09/01/2009 08:57 FA 55556015/1 1
AAA  35111_DDD   -----            -----            OI 0/0
AAA  35111_EEE   03/20/2008 11:27 03/20/2008 11:40 SU 38917388/2
AAA  35111_FFF       -----            -----            OI 0/0
AAA  35111_GGG         -----            -----            

Compose all these commands into a shell script. Thats all ?! Or clarify better why you want all these to be clubbed in to single command ?

Why don't you merge the two following lines (the second line starts with spaces) ?

35111_AAA         -----            -----            OI 0/0
  35111_BBB        -----            -----            IN 0/0

Jean-Pierre.

You can start with:

awk 'END { print r }
$1 ~ /_/ && r { print r }
NR > 3 && NF { 
  $1 = $1
  r = (split($1, t, "_") > 1 ? t[2] : r) FS $0
  }' infile

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.

No sort/unique for now, just trying to format the text as of your last post.
P.S. Squeezed the white space characters, not sure if you want that, though ...

---------- Post updated at 05:25 PM ---------- Previous update was at 05:16 PM ----------

Oops, just saw you have only an "AAA" in your first column, is that correct?

yes it is correct... actually AAA is batch name... i need to add it at very first column in the fille

Where it comes from? Is it dynamic or fixed?