I'm trying to do something pretty simple but its appears more complicated than expected... I've lines in a text file, separated by the comma and that I want to output to another file, without the first field.
Input file:
file1,item, 12345678
file2,item, 12345678
file2,item, 12345678
In output I've got the following:
,item, 12345678
,item, 12345678
,item, 12345678
As you can see the spaces before 12345678 are kind of merged into one space only.
My code:
cat myfile | while read l_line
do
v_OutputFile=$(echo $l_line | awk -F',' '{print $1}')
echo $(echo $l_line | awk -F',' '{OFS = ",";$1=""; print $0}') >> ${v_OutputFile}
done
The issue seems to come from the echo command that removes the spaces. If I do an echo with the quotes it works well. For instance:
echo 'file1,item, 12345678' | awk -F, -v OFS="," '{$1="";print $0}'
But I could not find a solution to work this out with the while loop. Even by putting the quotes in my input file, it stills removes the spaces.
Thanks for your help !