Hi there!!
My first Post :)
My problem is as follows:
I have multiple text files in a folder, and I need to automatically format these text files to an CSV format. At the same time I need to add different Data to accommodate it to the MySQL database.
so for example I need to convert this:
--------------------------------------------------------------------------------
FILE 1
--------------------------------------------------------------------------------
ActiveTouchMeetingClient
AddressBook
Adobe Flash Player Plugin
CNXT_MODEM_PCI_VEN_14F1&DEV_2C06_hpZ1379z
Connection Manager
DirectDrawEx
DXM_Runtime
EditPlus 3
ENTERPRISE
F95DE19F-CF69-4b03-81B6-9EC050D20D3B
to This:
, 1, USERNAME2, ActiveTouchMeetingClient
, 1, USERNAME2, AddressBook
, 1, USERNAME2, Adobe Flash Player Plugin
, 1, USERNAME2, MODEM_PCI_VEN_14F1&DEV_2C06_hpZ1379z
, 1, USERNAME2, Connection Manager
, 1, USERNAME2, DirectDrawEx
, 1, USERNAME2, DXM_Runtime
, 1, USERNAME2, EditPlus 3
, 1, USERNAME2, ENTERPRISE
----------------------------------------------------------------------------
FILE 2
----------------------------------------------------------------------------
ActiveTouchMeetingClient
AddressBook
Adobe Flash Player Plugin
CNXT_MODEM_PCI_VEN_14F1&DEV_2C06_hpZ1379z
Connection Manager
DirectDrawEx
DXM_Runtime
EditPlus 3
ENTERPRISE
F95DE19F-CF69-4b03-81B6-9EC050D20D3B
to This:
, 2, USERNAME2, ActiveTouchMeetingClient
, 2, USERNAME2, AddressBook
, 2, USERNAME2, Adobe Flash Player Plugin
, 2, USERNAME2, MODEM_PCI_VEN_14F1&DEV_2C06_hpZ1379z
, 2, USERNAME2, Connection Manager
, 2, USERNAME2, DirectDrawEx
, 2, USERNAME2, DXM_Runtime
, 2, USERNAME2, EditPlus 3
, 2, USERNAME2, ENTERPRISE
Etc.. Etc.. up to 500 files doesn't matter.
As you can see the Second column needs to increment +1 on each file it loops through.
Maybe I took the wrong approach to this, and hopefully there's someone that's going to point me in the right direction.
Here's what I've got so far.
convertSwToCSV(){
cd $PATHTOBUILD
COUNT=60 [I]# THIS NEEDS TO BE THE LINE COUNT OF THE FILES INSIDE THE LOOP[/I]
for ((a=1; a <= $COUNT; a++))
do
for txtFiles in *; do
USERNAME=`cat $PATHTOHARDWARE$txtFiles | grep Logged | awk -F '\' '{print $2}'`
echo $USERNAME [I]#just to see if we are getting the correct info.[/I]
cat $txtFiles | awk '{sub(/^/, " , '${a}', '${USERNAME}', ");print}' > $txtFiles
done
done
}
####################
# Runtime starts here
#
convertSwToCSV
My Idea is to do a FOR LOOP to create the auto_increment numbers between the file. BUT I am at LOST on how to end the LOOP inside the for txtFiles in *; do.
Any help on this will be GREATLY appreciated.
Thanks guys, sorry for the big post.