![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| print screen | prashantchavan | AIX | 7 | 12-03-2007 04:06 AM |
| perl - print to a log file and screen | mjays | Shell Programming and Scripting | 6 | 08-21-2007 05:34 AM |
| print to screen and to file using awk?! | satnamx | Shell Programming and Scripting | 2 | 04-25-2006 10:33 AM |
| How to print contents on the screen? | aadba | UNIX for Advanced & Expert Users | 1 | 03-22-2004 07:45 AM |
| how to print screen in linux | vancouver_joe | UNIX for Dummies Questions & Answers | 2 | 01-16-2002 12:51 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have the following questions regrading Unix commands.
1. Could you provide the commands how to print the content of .profile and .shrc files on the screen using more and piple command? or a better way? 2. How can i use the head and tail to display lines from 25 through 75... or a better solution? 3. How to search the /etc/password that begins with character with the character "a"? Thank you much in advance! -Ryan |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Re: How to print content on the screen
Quote:
cat filename | more Quote:
head -n 75 filename | tail -n 51 limitation: this assumes that the lines 25-75 do exist Quote:
awk '{ if( substr($0, 1, 1) == "a" ) print $0 }' /etc/password (requires sufficient authorization) I'm by no means an expert, there may be better ways in all cases. regards, ropers |
|
#3
|
||||
|
||||
|
to add to the 25 through 75 line problem:
Code:
filelength=`wc -l "filename" | awk '{print $1}'`
if [ $filelength -gt 74 ]; then
linesshort=0
else
let "linesshort = 75 - $filelength"
fi
let "tailnumber = 51 - $linesshort"
cat -n "filename" | head -n 75 | tail -n $tailnumber
There very likely is a MUCH easier way of doing this, but I don't know it. |
|
#4
|
|||
|
|||
|
A Perl script can be written to dump the file contents between two line numbers:
body.pl Code:
#!/usr/bin/perl -w
my ($file, $s, $e) = @ARGV;
$s > $e and ($s, $e) = ($e, $s);
my $ln = 0;
open FILE, "<$file";
while ($line = <FILE>) {
++$ln;
if ($ln >= $s && $ln <= $e) {
print $line;
}
}
close FILE;
# Print lines 25--75 ./body.pl somefile.txt 25 75 |
|
#5
|
||||
|
||||
|
Here's a unix command that lets you print file content between two specified line numbers...
sed -n '25,75p' file1 And another... awk 'NR>=25 && NR<=75' file1 |
||||
| Google The UNIX and Linux Forums |