How to edit a txt file ?

Hi,

I need to edit a text file which is like this..

-- D3341000600	AGEC901164   XYZ	SE0109	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3341000600	AGEC901164   XYZ	SE0109	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3341006000	AGEC921472   XYZ	SE0109	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3341006000	AGEC921472   XYZ	SE0109	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3213716600	DCEC160720   XYZ	RZ9191	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3213716600	DCEC160720   XYZ	RZ9191	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3213716300	DCEC169043   XYZ	RZ9191	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3213716300	DCEC169043   XYZ	RZ9191	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3213716100	DCEC197234   XYZ	RZ9191	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21
-- D3213716100	DCEC197234   XYZ	RZ9191	1RNVX	AH	2009-01-19	2009-01-11	2009-01-21


I need to get it like this..

 D3341000600|AGEC901164   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3341000600|AGEC901164   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3341006000|AGEC921472   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3341006000|AGEC921472   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3213716600|DCEC160720   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3213716600|DCEC160720   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3213716300|DCEC169043   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3213716300|DCEC169043   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3213716100|DCEC197234   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
 D3213716100|DCEC197234   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
  

I tried with this code.. but its not working.. the script is not terminating.. and the log file is empty..

#!/bin/ksh


for name in `cat data.txt`
do
cat $name |cut -f2,3,4,5,6,7,8,9|tr '\t' '|' > processed_data.txt
done

if [ $? -eq 0] ; then echo " Prcocessing completed."
else echo "script failed"
fi

Please help..

Thanks,
RRVARMA

One way:

awk 'BEGIN {OFS="|"}
{print $2,$3"   "$4,$5,$6,$7,$8,$9,$10}
' file

Regards

You can do the folowing

first save the folowing code in a file and u can name it as awk1

the code have to be in the same line (all of it) :

/--/{printf"%-11s|%-13s%-3s|%-6s|%-5s|%-2s|%-10s|%-10s|%-10s\n",$2,$3,$4,$5,$6,$7,$8,$9,$10 }

then do the command

awk -f awk1 file > output

BR

Not sure of your problem, but spacing could have been an issue around certain commands. At any rate, the following command and result is what I just got (I am using bash):

> cat data.txt | cut -c4-200 | cut -f1-8 | tr "\t" "|"
D3341000600|AGEC901164   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3341000600|AGEC901164   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3341006000|AGEC921472   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3341006000|AGEC921472   XYZ|SE0109|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3213716600|DCEC160720   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3213716600|DCEC160720   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3213716300|DCEC169043   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3213716300|DCEC169043   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3213716100|DCEC197234   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21
D3213716100|DCEC197234   XYZ|RZ9191|1RNVX|AH|2009-01-19|2009-01-11|2009-01-21

To send to a file, just add the appropriate command at the end of the line:
cat data.txt | cut -c4-200 | cut -f1-8 | tr "\t" "|" >processed_data.txt

You don't cat individual lines of data; cat expects a file name argument. But looping over individual lines is pretty pointless anyway, as both cut and tr can handle multi-line data. Simply replacing tabs with pipes and discarding the first three characters should suffice, right?

tr '\t' '|' <data.txt | cut -c3- >processed_data.txt

By the by, it's more elegant to run the command inside the if:

 if tr '\t' '|' <data.txt | cut -c3- >processed_data.txt; then
  echo Success
else
  echo Failure
fi

The printing of a message when the script is already done is not very useful as such; the user will see that the script has finished when the prompt returns, and the exit code will indicate the status. (Neither cut not tr can really fail, unless you have invalid syntax, so the only possible failure I see here is a disk or file system failure.)