LinuxQuestions.org
Register a domain and help support LQ
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, 12:37 PM   #1
Hammett
Senior Member
 
Registered: Aug 2003
Location: Barcelona, Catalunya
Distribution: Gentoo
Posts: 1,037

Rep: Reputation: 54
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, 12:42 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
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 12:43 PM.
 
Old 11-28-2004, 01:50 PM   #3
Hammett
Senior Member
 
Registered: Aug 2003
Location: Barcelona, Catalunya
Distribution: Gentoo
Posts: 1,037

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

Rep: Reputation: 61
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, 07:29 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:29 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 07:52 PM
bash scripting question mehesque Programming 2 03-07-2004 02:37 PM
Bash scripting question. welby Linux - Software 1 01-14-2004 11:05 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 10:06 AM


All times are GMT -5. The time now is 06:36 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration