analyze lines in a file by loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers analyze lines in a file by loop
# 1  
Old 01-12-2012
analyze lines in a file by loop

Hi Dears,

I use the below code to analyze lines in a file:

Code:
for line in `cat ucsv`
do
        echo $line
        //analyze statements
done

however, if line contains space char, it will be broken. for example, if file content is:

Code:
#login,full name,email,project,role,action
gmwen,Bruce Wen,wengm@foxmail.com,bt,qa,add

echo statement above will print as following:
Code:
#login,full
name,email,project,role,action
gmwen,Bruce
Wen,wengm@foxmail.com,bt,qa,add

But the expectation is:

Code:
#login,full name,email,project,role,action 
gmwen,Bruce Wen,wengm@foxmail.com,bt,qa,add

How to fix the issue?

Last edited by crest.boy; 01-12-2012 at 11:32 PM..
# 2  
Old 01-12-2012
Code:
$ tr " " "\n" < test.txt
#login,full
name,email,project,role,action
gmwen,Bruce
Wen,wengm@foxmail.com,bt,qa,add

# 3  
Old 01-12-2012
Quote:
Originally Posted by itkamaraj
Code:
$ tr " " "\n" < test.txt
#login,full
name,email,project,role,action
gmwen,Bruce
Wen,wengm@foxmail.com,bt,qa,add

Sorry, but what I expected is to avoid the broken issue.
# 4  
Old 01-12-2012
Code:
 
while read line
do 
echo $line; 
done < test.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to analyze sosreport file that I generated.?

Hello Team, Could You give me some hints how I should review the sosreport that I generated? I know how to analysis the SAR files however sosreport is my last hope - python script has hunged and I would like to know the root cause - for this is not performance issue. Thanks in advance! ... (3 Replies)
Discussion started by: nsmcny
3 Replies

2. Shell Programming and Scripting

Using sed in a loop/to remove lines contained in variable from file

I've tried numerous commands, but I am not sure how to use sed in a loop. This is what I have: VARZ contains CARD_FILE_LIST and it also contains CARD_FILE_LIST2 so echo "$VARZ" CARD_FILE_LIST CARD_FILE_LIST2 I have a file with 60 lines in /tmp/testfile it and I want those lines deleted... (3 Replies)
Discussion started by: newbie2010
3 Replies

3. Shell Programming and Scripting

ksh Loop through file one, remove lines from file two

Good Afternoon, I start with a file named biglist.txt. I have another file smallerlist. txt I want to remove the lines from smallerlist.txt from biglist.txt and leave those lines that do not reside in smallerlist.txt. Thanks !! (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

5. Programming

Using c++ to analyze two file problem

Hi, I have two files: Input_file1.txt 124 235 152 178 156 142 178 163 159 Input_file2.txt 124|5623 452|6698 178|9995 235|7542 159|8852 (1 Reply)
Discussion started by: cpp_beginner
1 Replies

6. UNIX for Dummies Questions & Answers

How to analyze file hashing

What command should I use to analyze file hashing of fixed flat files. How much work does it take for multiple flat files. (3 Replies)
Discussion started by: jbjoat
3 Replies

7. Shell Programming and Scripting

Find and analyze variable Strings in a large file.

Hi guys, I have multiple files (>5000) which I have in a folder. I read every file name and put it in a tmp variable "i" so that i can use it in the following task. I have a large .txt file (>50 MB) in which I want to find the variable "i" and the lines after this variable, so that I can use... (4 Replies)
Discussion started by: Ashitaka007
4 Replies

8. Shell Programming and Scripting

How to use while loop in bash shell to read a file with 4 lines of gap

Hi , I am currently using the while loop in bash shell, as follows. while read line do echo $line done < file.txt However, i want to use the while loop on file.txt, which will read the file with 4 lines of gap. Ex- if file.txt is a file of 100 lines, then i want to use the loop such... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

9. Shell Programming and Scripting

Loop through file and write out lines to file(s)

Hi, I am new to ksh scripting so your help will be much appreciated. I have a file called file.txt which looks like this Header 20050702 20050703 ABC DEF Header 20050703 20050704 123 456 Header 20050704 20050705 XXX YYY What I am trying to do is write out each of the record... (7 Replies)
Discussion started by: Jtrinh
7 Replies

10. UNIX for Dummies Questions & Answers

Loop through the lines in a file?

How do I loop through the lines of a file? Each line of the file will be the name of a server. Like: server1.stuff.com server2.stuff.com For each server I want to do a secure copy of the file to the other server. This will be a cron job so I guess it needs to run in just SH. I... (3 Replies)
Discussion started by: jimmy
3 Replies
Login or Register to Ask a Question