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 > 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
How to convert C source from 8bit chars to 16bit chars? siegfried Shell Programming and Scripting 0 09-26-2007 02:26 PM
catching some errors bebop1111116 Shell Programming and Scripting 5 09-29-2006 01:12 PM
Catching all Exit Codes Sivaswami J Shell Programming and Scripting 3 02-16-2006 07:13 PM
Catching signal and piping joseph_ng High Level Programming 7 11-14-2005 11:04 AM
catching interrupts toughguy2handle UNIX for Dummies Questions & Answers 1 09-19-2005 03:17 PM

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 11-21-2005
Gerry405 Gerry405 is offline
Registered User
  
 

Join Date: Jun 2005
Location: Alexandria, Scotland
Posts: 46
Awk- catching the last two chars

Can anyone explain to me how to get the last two chars' from each row of Column (each row being variable in length) using awk, some of the lines will be blank, I'll be running a paste after awking. So I need to keep the blanks where they are..so I can paste back all columns in the correct order

I see posts about stripping the last chars but nothing on getting the last chars

ie
GASTRO A9
NEONATALAF
GER.ASAB

GASTRO A9
ORSUR D3
GASTRO A9
GER.AS AB
GER.AP AB
NEONATALAF

output :

A9
AF
AB

A9
D3
A9
AB
AB
AF
  #2 (permalink)  
Old 11-21-2005
Corrail Corrail is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 50
Question Suggestion

Maybe something like....
grep -C 2> filename
? im not sure im trying to learn grep, awk, and sed so im not sure. if anyone can explain what i did wrong please do. How i came up with my solution is grep for searching -C because in man grep it says -C means print num lines of output context and 2> for 2 before the end of the line. I am most likely wrong but if someone can show the right way and explain why im wrong it would be greatly appreciated. Thanks
  #3 (permalink)  
Old 11-21-2005
Corrail Corrail is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 50
Another suggestion if the otherone doesnt work

sed -n '/STRING/,$p' filename|head -$n
Thats what i found while floating around on the forums now maybe you could change head to foot and possible make it so instead of the line and 2 more lines print, change it to make the last 2 character print? Idk maybe this will help you realize what you need or something? But can someone let me know whats wrong with this if it doesnt work maybe?
  #4 (permalink)  
Old 11-21-2005
grasper grasper is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 45
I can't think of anything in awk I'm afraid. I would have thought it'd be custom made for that job (in fact I'm sure someone who knows more will give you a very simple command, but I've drawn a blank), but with sed you could use:

sed 's/^.*\(..\)$/\1/' input_file
  #5 (permalink)  
Old 11-21-2005
Gerry405 Gerry405 is offline
Registered User
  
 

Join Date: Jun 2005
Location: Alexandria, Scotland
Posts: 46
awk filtering the last two characters at end of line

thanks for that I'll give it a try in the morning when I get to work...
  #6 (permalink)  
Old 11-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
nawk '{print substr($0, length($0)-1)}' myFile.txt
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:42 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