Answer» hi again.... as usual i'm here to seek help. hope all of you expert can guide me here
so.... i have a folder that contain many files. These file contain data that is needed to be inserted to db. I would like to append this filename into the file as ANOTHER column of data. but i dont know how to append this file name.
Folder A actA.txt actB.txt actC.txt
in every act* file, the format of data is like this (example below is actA.txt)
act111 61897689 act222 61891791 act333 66688844
if can, i would like to combine all those txt file into one, which i'll use
cat act* > allAct.txt
the output i desire is like this (take the file name and add another column into data)
act111 61897689 actA act222 61891791 actA act333 66688844 actA act555 45454545 actB act777 54545544 actB act999 22222656 actC
can it be done? or should i just seperate those file like below. (but i still dont know how to do it)
actA.txt act111 61897689 actA act222 61891791 actA act333 66688844 actA
actB.txt act111 61897689 actA act222 61891791 actA act333 66688844 actA
PLEASE help me coz i've tried it for several WEEKS but still cant find it solutions. All of your help and reply i appreciated and in advance thank you for all your helpIf this is a class project, which tools have you been taught to use so far?
If this is not a class project, are you open to us providing a solution using a scripting language? (Shell script, PHP, Perl, etc.)This is not class project. I'm doing development for organization i'm working right now to do some reporting for the company data. I'm new staff here and this is the FIRST time for me in script(unix) environment beacuse it is used here. I never knew and never be in project that involve shell script. More familiar with PHP, and Microsoft product i guess.
I need shell script language as the current program that support the data used it too. Please provide me solution in shell script. If u cant, just give me guidline and I can explore it myself afterward. I'm only familiar with cat, awk command. But i dont think it is possible to solve my problem doesnt it??
The solution i tried before
VAR=`ll -lrt act* | awk '{print $9}' #this will invoke the file name into variable VAR
then i try, to combine all the files
cat $VAR > act_all.txt
if put it into another column using cat awk command, the output was like below
the output (wrong) act111 61897689 actA act222 61891791 actB act333 66688844 actC act555 45454545 act777 54545544 act999 22222656
output(needed) act111 61897689 actA act222 61891791 actA act333 66688844 actA act555 45454545 actB act777 54545544 actB act999 22222656 actC
The amount(count) of data in each file is vary from each other. It count is different for each file, but will carry out the same format
I would appreciate if you're willing to help. Thanks
Code: [Select]for f in act* do SED "s/$/$f/" $f >> new1 done
|