The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can i read a file character by character karnan Shell Programming and Scripting 6 05-18-2008 11:22 PM
Count the number of occurence of perticular word from file rinku Shell Programming and Scripting 40 08-10-2007 04:33 PM
Can I read a file character by character? murtaza Shell Programming and Scripting 3 03-29-2007 08:19 AM
First Occurence kkm_job UNIX for Advanced & Expert Users 5 10-30-2006 02:37 PM
Pattern occurence in a file videsh77 UNIX for Dummies Questions & Answers 5 12-10-2004 03:41 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008
Read Only
 

Join Date: Jun 2006
Posts: 105
First occurence of character in a file

Hi All

I have the following contents in a file say in a file name called 'FILE1'

*********** Start of the file **************





SANDIO000456GROJ8900


SANDIO2338923GRJH900

*********** End of the file *******************

I want to cut the first line which has the characters. You may note that few lines of the file has blank lines in the start. Only after few lines you can see the strings.

In this case i want to get SANDIO000456GROJ8900.
Will this be possible in sed ? (Any direct single line command is appreciated)

Regards
Dhana
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 519
No offence Dhana, but do you ever actually try anything yourself first before posting here? You will never learn how to use these tools unless you try to figure things out for yourself.
Reply With Quote
  #3 (permalink)  
Old 05-12-2008
Smiling Dragon's Avatar
Disorganised User
 
Join Date: Nov 2007
Location: New Zealand
Posts: 674
How's about:
Code:
egrep -v '^$' | head -1
Reply With Quote
  #4 (permalink)  
Old 05-12-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 458
Quote:
Originally Posted by Annihilannic View Post
You will never learn how to use these tools unless you try to figure things out for yourself.
I agree !

How about:
Code:
grep '^[A-Z]' data.file | head -1
Reply With Quote
  #5 (permalink)  
Old 05-12-2008
Read Only
 

Join Date: Jun 2006
Posts: 105
First Occurence of character in a file

Hi
I tried with
cat filename|sed '^$d'|head -1

Even the examples provided by you did work.
Thank you so much.


Regards
Dhana
Reply With Quote
  #6 (permalink)  
Old 05-12-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 458
Quote:
Originally Posted by dhanamurthy View Post
cat filename|sed '^$d'|head -1
Dhana
First, that's Useless use of cat , second your snippet don't work. Maybe:
Code:
sed -n '/^[A-Z]/p' filename | head -1
Reply With Quote
  #7 (permalink)  
Old 05-12-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,473
one more and single command

Code:
awk '/^[A-Za-z]/{ print; exit }' filename
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:39 PM.


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

Content Relevant URLs by vBSEO 3.2.0