extracting single charachters

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting single charachters
# 1  
Old 11-04-2001
extracting single charachters


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

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?

# 2  
Old 11-04-2001
I would just use sed, something like this...
line="INFORM_USERS_IB COMPLETED llprod 20011003:100608"
echo "$line" | sed 's/[^:]*:\(..\)\(..\).*/\1:\2/'

# 3  
Old 11-04-2001
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?

. .
# 4  
Old 11-04-2001
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Paste 2 single column files to a single file

Hi, I have 2 csv/txt files with single columns. I am trying to merge them using paste, but its not working.. output3.csv: flowerbomb everlon-jewelry sofft steve-madden dolce-gabbana-watchoutput2.csv: http://www1.abc.com/cms/slp/2/Flowerbomb http://www1.abc.com/cms/slp/2/Everlon-Jewelry... (5 Replies)
Discussion started by: ajayakunuri
5 Replies

2. UNIX for Dummies Questions & Answers

Extracting combined differences based on a single column

Dear All, I have two sets of files. File 1 can be any number between 1 and 20 followed by a frequency of that number in a give documents... the lines in the file will be dependent to the analysed document. e.g. file1 1,5 4,1 then I have file two which is basicall same numbers but with... (2 Replies)
Discussion started by: A-V
2 Replies

3. Shell Programming and Scripting

Help extracting single instance of numbers which repeat

Hi, the title isn't very descriptive but it'll be easier to explain what I need if I write out the coordinates from which I need to extract certain information: ATOM 2521 C MAM X 61 44.622 49.357 12.584 1.00 0.00 C ATOM 2522 H MAM X 61 43.644 49.102 12.205 ... (10 Replies)
Discussion started by: crunchgargoyle
10 Replies

4. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

5. Shell Programming and Scripting

Replace single quote with two single quotes in perl

Hi I want to replace single quote with two single quotes in a perl string. If the string is <It's Simpson's book> It should become <It''s Simpson''s book> (3 Replies)
Discussion started by: DushyantG
3 Replies

6. OS X (Apple)

Automated command ; extracting files from folders and copying them into a single folder

Hello everyone, I'm running Mac OS X Leopard (10.5.8) and I want to use the Terminal to help automate this tedious and laborious command for me: I need to extract all of the .m4p files in my "iTunes Music" folder which reside in folders of the artist, and then subfolders for the albums and... (2 Replies)
Discussion started by: qcom
2 Replies

7. Shell Programming and Scripting

unzip single file and untar single file

Dear friends, My requirement below- 1] I have a zip file on unix server - ETL_Extracts_20100218175009.zip which is composed of various entity extracts namely... ENTITY1.txt, ENTITY2.txt, ENTITY3.txt etc.... How do I unzip only a single file ..say ENTITY2.txt from this zip file. CAn you... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

8. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

9. UNIX for Dummies Questions & Answers

Cutting the top two lines, and also charachters below.

Hey all. I have a file that I am trying to cut information out of. We have a script that shows us all of our Radio Scanners that are being used and I'm writing a script that clears all of the context off of the scanners. The script that runs shows us this information below... |emp_id ... (5 Replies)
Discussion started by: jalge2
5 Replies

10. UNIX for Dummies Questions & Answers

max charachters for usernames

Can anyone tell me what the charachter maximum on a username is in SunOs 5.6. Thanks Mark (1 Reply)
Discussion started by: m.szylkarski
1 Replies
Login or Register to Ask a Question

Featured Tech Videos