Please help to writeI want a Perl one liner to add-liner that checks whether the file name in startingfirst fields of thean input file is the file's name and, if it isn't, adds the file name doesn't exist as the first column on every line.
Example written in shell :
for f in *file*.csv; do file_column=`cat ${f} | awk -F',' '{print$1}'` if [ $file_column != ${f} ] then sed -i "s/^/$f,/" $f 2>/dev/null; fi done inBut the approach above example trying to take the first column and checking if it's same as file name , if it's same doing nothing else addingwhich checks whether the file name asis present in the first column.
But the above approach and adds it if it isn't, is taking ~3 Hours for 4 Laks files, As per my understanding perl. I understand that Perl is faster infor file operationoperations.
Perl which i haveThe Perl command I tried :
perl -p -i -e 's/^/Welcome to Hell,/' file*.csv pleasePlease help me to add the logiclogic to check if it already exist or not in file before doingwhether the field exists already and only change if it doesn't.
Input : file1.csv col1,col2,col3 data1,data2,dat3 Output: file1.csv file1.csv,col1,col2,col3 file1.csv,data1,data2,data3 or if here is any faster way please suggest. Perl one liner because it's part of another shell script so tiny call will be better i guess (suggest please)