grepping the first 3 characters from a file | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

grepping the first 3 characters from a file

UNIX for Dummies Questions & Answers


Tags
grep or

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-14-2001
g-e-n-o g-e-n-o is offline
Registered User
 
Join Date: Oct 2001
Last Activity: 8 April 2002, 11:58 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
grepping the first 3 characters from a file

Hi

I was wondering if it's possible to use a command to get the first 3 characters of a line in a text file, I tried grep but it returns the whole line but I am only interested in the first 3 characters. Is this possible with grep or I need any other command?

Also is it possible deleting from a position to another in VI? For example delete from posistion 1 to 10 in all lines, I searched the whole VI man page but I couldnt find anything, only how to delete lines and words


Cheers
Sponsored Links
    #2  
Old 10-14-2001
oracle8 oracle8 is offline
Registered User
 
Join Date: Sep 2001
Last Activity: 23 February 2009, 11:27 AM EST
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
U could grep the line out and then cut it.
grep 'text' filename | cut -c 1-3 should help.
As regards vi I do not think man pages will show you how.
But it can be easily done.
Sponsored Links
    #3  
Old 10-15-2001
maverick
Guest
 
Posts: n/a
In VI it is possible to delete from lines doing the following:

:1,5s!^[^|][^|]!!

This will delete from line 1 to 5 the first two charachters it comes across.

The ^ is beginning of the line and [^|] is each charchter you would want to delete.

All lines could be done with:

%s!^[^|][^|]!!


Hope it helps

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grepping file and returning passed variable if the value does not exist in file at all. personalt Shell Programming and Scripting 3 04-28-2011 03:24 AM
Grepping for hex characters - explanation? mregine Shell Programming and Scripting 7 01-27-2011 01:03 PM
Grepping log file x-plicit78 Shell Programming and Scripting 19 10-22-2009 08:14 AM
Grepping characters anushree.a Shell Programming and Scripting 3 04-23-2009 05:43 AM
grepping the first 3 characters from a file rachael UNIX for Dummies Questions & Answers 2 10-15-2001 02:33 PM



All times are GMT -4. The time now is 02:17 AM.