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
Extracting lines between 2 strings only if the pattern patches simran Shell Programming and Scripting 5 04-23-2008 05:58 PM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 03:25 AM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 11:27 AM
extracting lines from a file pradeepthanraj Shell Programming and Scripting 1 11-15-2005 09:41 AM
Help required regarding Extracting lines from a file google_ever Shell Programming and Scripting 1 10-12-2005 08:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-03-2008
trichyselva trichyselva is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 65
extracting lines from a file

i want to extract lines 5 and 7 from a txt file which contains nearly 20 entries how to do it
also i want to check whether the 42nd character is 'S' in that line

suggestions welcome
  #2 (permalink)  
Old 03-03-2008
am_yadav am_yadav is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chandigarh,India
Posts: 22
Do you want to extract both lines in same command?
  #3 (permalink)  
Old 03-04-2008
trichyselva trichyselva is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 65
Quote:
Originally Posted by am_yadav View Post
Do you want to extract both lines in same command?
no not needed
in different commands
  #4 (permalink)  
Old 03-03-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,557
Quote:
Originally Posted by trichyselva View Post
i want to extract lines 5 and 7 from a txt file which contains nearly 20 entries how to do it
take some inspiration from here

Quote:
also i want to check whether the 42nd character is 'S' in that line
suggestions welcome
see here if you are using bash.
under "substring extraction". then check with if/else statement
  #5 (permalink)  
Old 09-02-2008
Sujan Banerjee Sujan Banerjee is offline
Registered User
  
 

Join Date: Sep 2008
Location: BLR,INDIA
Posts: 3
Hi TrichySelva,
Sorry for Late response(Actually I joined this forum today itself!!)
To extract line number 5 and 7,use:
bash-2.03# sed -n '5p;7p' cricketnews

5 and if Pakistan, as expected, beat Bangladesh the day after,
7 the virtue of having won more matches in the Super Four stage, Pakistan will go through.

To Extract Say Line 4-6,12-15 and 32 to last,do this:
bash-2.03# sed -n '4,6p;12,15p;32,$p' cricketnews

4 ousted from the event. If India lose to Sri Lanka on Thursday,
5 and if Pakistan, as expected, beat Bangladesh the day after,
6 both teams will be tied on four points. In that scenario, by
12 the CB Series in Australia. Therein lies the story: the CB
13 Series was played in Australia, the Asia Cup is being
14 played in Pakistan. And the Indian bowlers react differently
15 to the two types of conditions.
32 to struggle on pitches that give him zero assistance.
33 Dhoni thought the bowlers gave it their all, but
34 the pitch was just too unresponsive.

To Extract say 25th to 30th(To extract 42nd char-just write 42) char and 34-38char of each of these lines,
bash-2.03# sed -n '4,6p;12,15p;32,$p' cricketnews|cut -c25-30,34-38
eventf Ind
, as ected,
be tion fo
in Auslia.
yed instral
stan. the
es of ditio
pitchthat
the bors ga
just tunres

bash-2.03# sed -n '4,6p;12,15p;32,$p' cricketnews|cut -c42
l
a
p
r

i

e
i
s

Hope it solves ur purpose,though sadly bit too late I believe

Sujan Banerjee
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0