Saturday, 17 August 2013

Unix: how to read line's original content from file

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?

No comments:

Post a Comment