How to cut one line instead of colume

How to cut one line instead of colume

Post by Gareth Youn » Fri, 28 Jan 2000 04:00:00



Dear all,

Is there any one can show me how to get a single line from a test file. What
command should I use and how?

Best Regards,
GY

 
 
 

How to cut one line instead of colume

Post by Eike Rietze » Fri, 28 Jan 2000 04:00:00


using ksh:
read VARIABLE < testfile
or
VARIABLE=`line < testfile`

Eike


> Dear all,

> Is there any one can show me how to get a single line from a test file. What
> command should I use and how?

> Best Regards,
> GY

--
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Eike Rietzel
Gesellschaft fuer Schwerionenforschung
Biophysik
Planckstr. 1
64291 Darmstadt
fon: +49-6159-71-2156
fax: +49-6159-71-2106
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

 
 
 

How to cut one line instead of colume

Post by Matthew Land » Fri, 28 Jan 2000 04:00:00



> using ksh:
> read VARIABLE < testfile
> or
> VARIABLE=`line < testfile`

> Eike

That's good for getting the FIRST line of the test file.  To get line 6
try:

  sed -n '6p' datafile

To get a the 4th line that doesn't have a # as the first char, try:

  sed -n  '/^[^#]/p' datafile |sed -n '4p'

It really depends on what you consider your "line" requirements.

 - matt

--

  AIX and HACMP Certified Specialist    | |  / \ |\| |  \. ,_|    _| --
  / Comments, views, and opinions \     | |_/ ^ \|   | ) | |      \, *_)
  \ are mine alone, not IBM's.    /     |___|/~\_\_|\|__/|_|        \(

 
 
 

How to cut one line instead of colume

Post by Tristan Quaif » Fri, 28 Jan 2000 04:00:00


Or in an awk you might do:

awk 'NR==6' testfile

(to get the 6th line)

Tristan.



> > using ksh:
> > read VARIABLE < testfile
> > or
> > VARIABLE=`line < testfile`

> > Eike

> That's good for getting the FIRST line of the test file.  To get line 6
> try:

>   sed -n '6p' datafile

> To get a the 4th line that doesn't have a # as the first char, try:

>   sed -n  '/^[^#]/p' datafile |sed -n '4p'

> It really depends on what you consider your "line" requirements.

>  - matt

 
 
 

How to cut one line instead of colume

Post by Ken Pizzi » Sat, 29 Jan 2000 04:00:00



>Is there any one can show me how to get a single line from a test file. What
>command should I use and how?

If the $n variable contains the number of the line to be shown:
  n=8
  sed "${n}q;d"
or, hardwiring the line number:
  sed "8q;d"

This also works if $n is a regular expression contained in /s:
  n='/foo/'
  sed "${n}q;d"
or:
  sed '/foo/q;d'

                --Ken Pizzini