Question

I have a file with the following content (I placed 3 lines for example):

12743002785468    |MOVIL APPLE IPHONE4 16GB BLANCO         |NVEN          |Centro de Atención  VIP            |0862034032
12747002147595    |MOVIL APPLE IPHONE4 16GB BLANCO         |NVEN          |Centro de Atención  VIP            |0862033996

I have a variable date (20140430) I want to concatenate the beginning of each record like this:

20140430|12743002785468    |MOVIL APPLE IPHONE4 16GB BLANCO         |NVEN          |Centro de Atención  VIP            |0862034032
20140430|12747002147595    |MOVIL APPLE IPHONE4 16GB BLANCO         |NVEN          |Centro de Atención  VIP            |0862033996

I tried to use this:

cat /home/file.txt | awk '{print "'"20140430"'""|"$0;}' > /home/file.txt

and

sed -i 's/^/20140430|/' /home/file.txt > /home/file.txt

But not work and i could not do that to my file of 180,000 records. Anyone have another idea how I can concatenate? The operating system is SunOS 5.11 sun4v sparc sun4v 11.1 Thank you very much in advance

Was it helpful?

Solution

You can also loop and append:

while read line; do
   echo 20140430'|'$line
done < /home/file.txt > /home/file.txt.tmp
mv file.txt.tmp file.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top