![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Can I read a file character by character? | murtaza | Shell Programming and Scripting | 4 | 04-27-2009 05:51 AM |
| read a variable character by character, substitute characters with something else | vipervenom25 | UNIX for Dummies Questions & Answers | 2 | 06-06-2008 03:18 PM |
| Can i read a file character by character | karnan | Shell Programming and Scripting | 6 | 05-19-2008 02:22 AM |
| Read First Character of Each Line in File | azelinsk | Shell Programming and Scripting | 7 | 07-11-2007 08:15 PM |
| Edit and insert character in a text file | negixx | Shell Programming and Scripting | 3 | 06-10-2005 01:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Quote:
Code:
^ - from the beginning of the line
.\{3\} - any 3 characters
\(.\) - capture one character [the 4-th chars from the beginning]
.* - any number of characters
\1 - print the first 'capture'
|
|
|||||
|
Quote:
4 Quote:
1234 I don't know - depends on the the definition of 'works' |
|
||||
|
sed and awk wont work if the character you've got isn't on the first line of the file.
If you have GNU text utiliities installed you can do it using the versions tail and head in the distribution. head -c 4 yourfile.txt | tail -c 1 If you wanted the 4th charcter for example. However this counts carriage returns and spaces as characters. If you want to ignore spaces and/or carraige returns you can do it but its a little more complicated. It would be easy if you have access to perl: cat youfile.txt | perl -e 'read(STDIN,$data,4); print substr($data,-1);' again gives your the 4th character. Sean |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|