awk code help for displaying file contents
Hi folks,
I am trying to display the contents of a file from given line no. to the total no. of lines. I tried upto some code but its not giving the output I want. Please help me. Code:
#display the file contents from given line number to no of lines given |
You need to tell us where the problem is---what does the script do now? What are the error messages, etc.?
Does the awk statement work by itself in a terminal (without running the script)? Printing a range of line numbers is (for me) easier with SED. Example: Code:
sed -n '5,+10p' filename ##prints lines starting with #5, plus the next 10 lines Code:
file=`cat $a` |
Quote:
2. I think the problem is all with awk. 3. I am getting the output with sed as you said. But I want to insert arguments as user defined like $s and $t. How can I do that? 5. Am I not do this with the help of awk? |
Again, run the awk statement by itself in a terminal. First, run it with fixed values instead of variables.
You did not address this question: Quote:
Code:
sed -n "${start},+${num}p" filename ##starts on the value of "start" and prints more lines per the value of "num". |
if you want to use bash
Code:
checkdigit(){ if you want awk Code:
read -p "Enter the file name: " FILENAME |
Quote:
Quote:
Code:
sed -n '${$s},+${$t}p' $a Code:
sed: -e expression #1, char 13: unterminated `s' command |
If you want to run the SED command using the values of the variables "s" and "t", then you want this:
Code:
sed -n "${s},+${t}p" $a Quote:
Third request: Run the AWK command by itself to make sure that it is working as you expect. |
I am not as good as you in shell scripting can you explain me some lines in your code?
Quote:
Quote:
Quote:
|
Read the man page for the "read" command. For example, the -p option puts the prompt on the same line.
|
Quote:
For more information, browse to http://www.gnu.org/software/bash/manual/bashref.html and search for extglob. |
Quote:
Can you explain me? |
Quote:
http://www.grymoire.com/Unix/ |
Quote:
Code:
... 'NR>=s && NR<=e{ print $0 }' ... |
Thanks one and all for your replies.... :)
|
All times are GMT -5. The time now is 10:56 AM. |