The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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? murtaza Shell Programming and Scripting 4 04-27-2009 05:51 AM
Can i read a file character by character karnan Shell Programming and Scripting 6 05-19-2008 02:22 AM
Count the number of occurence of perticular word from file rinku Shell Programming and Scripting 40 08-10-2007 07:33 PM
First Occurence kkm_job UNIX for Advanced & Expert Users 5 10-30-2006 06:37 PM
Pattern occurence in a file videsh77 UNIX for Dummies Questions & Answers 5 12-10-2004 07:41 AM

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

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
  #2 (permalink)  
Old 05-12-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
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.
  #3 (permalink)  
Old 05-12-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
How's about:
Code:
egrep -v '^$' | head -1
  #4 (permalink)  
Old 05-12-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,419
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
  #5 (permalink)  
Old 05-12-2008
dhanamurthy dhanamurthy is offline
Registered User
  
 

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
  #6 (permalink)  
Old 05-12-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,419
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
  #7 (permalink)  
Old 05-13-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
one more and single command

Code:
awk '/^[A-Za-z]/{ print; exit }' filename
Sponsored Links
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 05:05 AM.


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