![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| print line whatever line i want in a file... there any way | kittusri9 | Shell Programming and Scripting | 1 | 05-15-2008 09:37 AM |
| How to print 3rd to last line of file? | NivekRaz | Shell Programming and Scripting | 2 | 09-10-2007 05:04 PM |
| how to print 35th line from a file ? | gridview | UNIX for Dummies Questions & Answers | 9 | 05-15-2007 01:31 PM |
| how to print out line numbers of a text file? | forevercalz | Shell Programming and Scripting | 4 | 12-12-2005 01:04 AM |
| Print one line of Existing File | danhodges99 | UNIX for Dummies Questions & Answers | 2 | 02-25-2003 07:56 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Print file line by line
I have a file where each line is a stream of text as follows,
table1, select * from table1 table2, select * from table2 How do i loop through the file line by line? I have tried doing the following for line in `cat file.txt` do echo $line done and ... cat file.txt|while read line do echo "$line" done but the output produced by the echo is table1, select * from table1 ...etc etc... Any help? |
| Forum Sponsor | ||
|
|
|
|||
|
hm, the "for"-loop will not be working for the following reason: "for" will split up its argument at word boundaries and cycle through them:
a="1 2 3 4 5" for value in $a ; do print - $value done will yield: 1 2 3 4 5 The while-loop in conjunction with "read" is the correct way to do it: cat file | while read line ; do print - "$line" done should print out "file" line by line. If not, try the following: load your script into vi and in command mode issue ":set list" to display all the nonprintable characters. Sometimes the shell reacts a bit picky when facing these. If this doesn't correct your problem do the same with your input file, maybe there are nonprintig characters hidden in it which prevent print/echo from working correctly. bakunin |