![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| 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 12:37 PM |
| How to print 3rd to last line of file? | NivekRaz | Shell Programming and Scripting | 2 | 09-10-2007 08:04 PM |
| how to print 35th line from a file ? | gridview | UNIX for Dummies Questions & Answers | 9 | 05-15-2007 04:31 PM |
| how to print out line numbers of a text file? | forevercalz | Shell Programming and Scripting | 4 | 12-12-2005 05:04 AM |
| Print one line of Existing File | danhodges99 | UNIX for Dummies Questions & Answers | 2 | 02-25-2003 11:56 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 Code:
for line in `cat file.txt` do echo $line done Code:
cat file.txt|while read line do echo "$line" done table1, select * from table1 ...etc etc... Any help? Last edited by Yogesh Sawant; 04-10-2009 at 06:19 AM.. Reason: added code tags |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|