LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-28-2004, 11:37 AM   #1
Hammett
Senior Member
 
Registered: Aug 2003
Location: Barcelona, Catalunya
Distribution: Gentoo
Posts: 1,074

Rep: Reputation: 59
Question Bash scripting question


Hi all!!

I would like to make a script that will output one specific line of a filetext, ie, if a put "script -10 filetext.txt" the output will be the 10th line of that file.

I've been looking around with "cat" and "more", but I'm totally lost.
Any help is appretiated
 
Old 11-28-2004, 11:42 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
script:
Code:
#!/bin/bash
head -n $1 $2 | tail -n 1
usage:
Code:
script 20 file

Last edited by acid_kewpie; 11-28-2004 at 11:43 AM.
 
Old 11-28-2004, 12:50 PM   #3
Hammett
Senior Member
 
Registered: Aug 2003
Location: Barcelona, Catalunya
Distribution: Gentoo
Posts: 1,074

Original Poster
Rep: Reputation: 59
Many thanks !! ^_^
 
Old 11-29-2004, 02:45 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
cat file.txt | sed -n "10 p"
or
sed -n "20 p" file.txt

10 or 20 here being the line number.

Yves.
 
Old 11-29-2004, 06:29 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i looked at grep for that directly. forgot sed. doh.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting question ajaye1971 Linux - Newbie 1 11-16-2005 07:29 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 06:52 PM
bash scripting question mehesque Programming 2 03-07-2004 01:37 PM
Bash scripting question. welby Linux - Software 1 01-14-2004 10:05 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration