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
need help extracting this part finalight Shell Programming and Scripting 6 05-20-2008 03:03 AM
extracting from tar.bz2 Raom UNIX for Advanced & Expert Users 1 03-07-2006 06:33 AM
Cutting the top two lines, and also charachters below. jalge2 UNIX for Dummies Questions & Answers 5 08-02-2005 11:59 AM
extracting from a string preetikate Shell Programming and Scripting 1 03-11-2004 04:08 AM
max charachters for usernames m.szylkarski UNIX for Dummies Questions & Answers 1 02-01-2002 07:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2001
Registered User
 

Join Date: Nov 2001
Posts: 2
Stumble this Post!
extracting single charachters

Hello!

brand new to unix (let alone scripting) I have come hit a step I can't seem to get around.

in a text file I have information such as :-

INFORM_USERS_IB COMPLETED llprod 20011003:100608

What I need to do is extract the 55th and 56t charachter, then insert a : then extract the 57th and 58th.. to give me an end result of:-
10:06

problem is how do I count of extract these charachters as they change frequently but *should* stay in the correct position??
(also does tab count as a single char?)

Or is there an easier way to reformat a date and time string?

Cheers,
James
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-04-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,424
Stumble this Post!
I would just use sed, something like this...
Code:
line="INFORM_USERS_IB COMPLETED llprod 20011003:100608"
echo "$line" | sed 's/[^:]*:\(..\)\(..\).*/\1:\2/'
Reply With Quote
  #3 (permalink)  
Old 11-04-2001
Registered User
 

Join Date: Nov 2001
Posts: 2
Stumble this Post!
there are approximately 20 similar lines for each title
"INFORM_USERS_IB " and the times will update.
is it possible to format each line sequentially using the second line of code, that way bypassing the need to define changing lines?

thanks
.
. .
Reply With Quote
  #4 (permalink)  
Old 11-04-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,424
Stumble this Post!
You lost me there, but the sed statement should work for any similiar line. I just posted an easy way to demo it.

The sed statement discards all characters up to and including the colon. The next two chars are saved. Then a colon is inserted. Then the next two chars are saved. Everything else is discarded.

So as long as the time is the 4 chars following the first colon on the line everthing should be fine.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:38 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