![]() |
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 |
| How can i read a non text file in unix - ELF-64 executable object file - IA64 | alexcol | UNIX for Advanced & Expert Users | 8 | 11-07-2008 08:56 AM |
| Read text file from a specified string to the end | bsrajirs | UNIX for Advanced & Expert Users | 9 | 01-11-2008 01:05 AM |
| read specific text from a log file | ragha81 | Shell Programming and Scripting | 4 | 10-17-2006 01:17 PM |
| need to read 3° character from a text file | piltrafa | UNIX for Dummies Questions & Answers | 15 | 07-26-2005 10:19 AM |
| help with cshell script to read 1 or more lex files | homerj546 | Shell Programming and Scripting | 1 | 04-18-2004 10:01 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Read text file in Cshell
I've been searching the forums for info on reading a text file in a Cshell script but nothing I'm trying is working. My latest attempt was:
set LASInputFile = `ls *.[Ll][Aa][Ss] | head -1` echo $LASInputFile while read line do echo $line done < $LASInputFile My error message is: while: Expression syntax Thanks for any help Paul Hudgens Denver |
|
||||
|
Code:
set LASInputFile = `ls *.[Ll][Aa][Ss] | head -1` set i=`cat $LASInputFile | wc -l` set j=1 while ($j <= $i) set line=`cat $LASInputFile | head -$j | tail -1` @ j = $j + 1 # do your thing with $line here. # for this example, we'll just echo # it back the screen echo $line end |
|
||||
|
I'm getting the error message: Unknown user: VERSION
The following is the first line of my file: ~VERSION Some of the lines in my file begin with a tilde. Is that causing a problem? Also I'm setting i=100 since what I'm after is in the top 100 lines of an otherwise very long file. set LASInputFile = `ls *.[Ll][Aa][Ss] | head -1` echo $LASInputFile set j=1 while ($j <= 100) set line=`cat $LASInputFile | head -$j | tail -1` @ j = $j + 1 echo $line end Thanks for the help, Paul H. |
|
||||
|
Sorry, I've made some slight changes to your script:
Code:
set LASInputFile = `ls *.[Ll][Aa][Ss] | head -1` echo $LASInputFile set j=1 while ($j <= 100) set line="`cat $LASInputFile | head -$j | tail -1`" @ j = $j + 1 echo "$line" end |
| Sponsored Links | ||
|
|