The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-21-2004
Registered User
 

Join Date: Mar 2004
Posts: 2
Lightbulb How to print content on the screen

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  
Old 03-22-2004
ropers's Avatar
Registered User
 

Join Date: Dec 2001
Location: Dublin
Posts: 45
Re: How to print content on the screen

Quote:
Originally posted by aadba
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?
perhaps this?
cat filename | more
Quote:
2. How can i use the head and tail to display lines from 25 through 75... or a better solution?
perhaps this way?
head -n 75 filename | tail -n 51
limitation: this assumes that the lines 25-75 do exist
Quote:
3. How to search the /etc/password that begins with character with the character "a"?

Thank you much in advance!
-Ryan
perhaps this will work?
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  
Old 03-22-2004
ropers's Avatar
Registered User
 

Join Date: Dec 2001
Location: Dublin
Posts: 45
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
this should take care of the eventuality that the file in question is shorter than 75 lines.

There very likely is a MUCH easier way of doing this, but I don't know it.
  #4  
Old 03-22-2004
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,477
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;
I'm not aware of a Unix program that dumps file content between two specified line numbers, so I tend to write my own Perl script for this purpose as above. Just wrote this for fun though.

# Print lines 25--75
./body.pl somefile.txt 25 75
  #5  
Old 03-22-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0