Artificial intelligent assistant

Unix: how to read line's original content from file I have a data file, the content is as follows: department: customer service section: A department: marketing section: A department: finance section: A When I read each line, I would extract the department name using `cut` command. Unfortunately, the program will automatically `trim` all redundant space and thus I cut the department name incorrectly. cat dept.dat | while read line do echo $line echo $line | cut -c 12-29 done e.g. the original line is: department: marketing section: A While the program treats this line as: department: marketing section: A How can I read the line without trimming all the redundant space?

You are losing the spaces when you expand `$line`. Put double quotes around your variable expansion and you'll preserve the spaces:


$ cat dept.dat | while read line
> do
> echo "$line"
> echo "$line" | cut -c 12-29"
> done
department: customer service section: A
customer service
department: marketing section: A
marketing
department: finance section: A
finance

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 340a4bfcf865604ce5f8ed048f77eb91