realigning data string


 
Thread Tools Search this Thread
Operating Systems Solaris realigning data string
# 1  
Old 02-02-2006
realigning data string

Dear Forum members,

I am simply trying to take a 'string' or 'text' line from
inside a file( ex. '01020408')and then trying to grab positions
5 and 6, followed by 2 and 3, and so on. Basically realigning
the text to another file or to a variable in Shell.

What is the simplest way to do this? Can I use
CUT (to multiple Var's), or CASE, PRINTF, AWK, ..... ? I am not an expert
obviously, so I do not have a solid understanding of
AWK and SED commands for example. I obviously need something
that parses a line. I can then put the parsed pieces into place
using variables,etc.

Could you please give me your advice and syntax if possible?
Thank you,

Hman

Last edited by hman; 02-02-2006 at 11:55 PM.. Reason: New thoughts on question
# 2  
Old 02-03-2006
I would suggest sed(1). It allows you to slice and dice both fixed and variable length records. Using the (s)ubstitute command, you can identify columns and rearrange them as desired. Below is an example of reversing the order of 4 2-byte pairs:

echo "01020304" | sed -e "s/\(..\)\(..\)\(..\)\(..\)/\4\3\2\1/"
04030201

A strong grasp of regular expressions is very helpful.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut the data with a string that has \ in it

Hi Team, Here's the record in a file. abc\USER DEFINED\123\345\adf\aq1 Delimiter here is "\USER DEFINED\" Expected output: abc|123\345\adf\aq1 Find "\USER DEFINED\" and replace it with "|". Can anyone please help us to fix this issue? Please use CODE tags as required by... (5 Replies)
Discussion started by: kmanivan82
5 Replies

2. Shell Programming and Scripting

Perl :: to parse the data from a string.

Hi folks, I have a line in log from which I need to parse few data. Jul 6 00:05:58 dg01aipagnfe01p %FWSM-3-106011: Deny inbound (No xlate) From the above... I need to parse the %FWSM-3-106011: substring. Another example Jul 13 00:08:55 dq01aipaynas01p %FWSM-6-302010: 2 in use, 1661... (3 Replies)
Discussion started by: scriptscript
3 Replies

3. Programming

how to output data with only an specific string on it

hi! i made an sql script but i do not know how to just output all the lines that starts with an specific string. and that string, you will input it before i run the sql for example: INPUT NAME: JOHN i just want to output lines that starts with JOHN (2 Replies)
Discussion started by: engr.jay
2 Replies

4. Shell Programming and Scripting

extracting data from a string

Hi there, I have a bunch of vlan tagged network interfaces that are named as follows e1000g111000 e1000g99001 e1000g3456000 nge2002 where the 'e1000g' and 'nge' parts of the name are the driver, the red and blue bits above define the VLAN and the last digit on the end defines the... (3 Replies)
Discussion started by: rethink
3 Replies

5. Shell Programming and Scripting

Extract data from a string

Hi all, I want to extract "this_data" from the string below using awk <Bundle_Name>this_data</Bundle_Name> Any help would be appreciated (5 Replies)
Discussion started by: cillmor
5 Replies

6. Shell Programming and Scripting

Data after a string in a file

Hi, I have a file with data as follows: 324dsadfasfgf23<xmlsssssssssssssssssssssssssssssssssssssss<fdf>dfsdf> i need all the data followed by the string <xml? Is it possible to retrieve it? (1 Reply)
Discussion started by: Vijay06
1 Replies

7. Shell Programming and Scripting

Extracting data from a string containing &;

:confused: How can I exrtact the code HU52143N200401 from a string that contains &amp;gt;HU52143N200401&amp;lt; (10 Replies)
Discussion started by: gugs
10 Replies

8. UNIX for Dummies Questions & Answers

get the data in a file into single string

Hello everyone ! I need to get the data in a file into a string. file1 1 2 3 4 5 I need to write a script where the file1 info is stored in a string (say variable s). So the output should be 1,2,3,4,5 or (1,2,3,4,5) If i say echo $s or print $s output should be 1,2,3,4,5 or ... (7 Replies)
Discussion started by: i.scientist
7 Replies

9. Programming

FILE to String data types

Hi, I am trying to read a FILE data type into a String data type, I tried to make the FILE* veriable just equal the String veriable but i get: Conversion from 'FILE*' to 'String' is ambiguous Has anyone got any idea? Thanks (4 Replies)
Discussion started by: cb.mark
4 Replies

10. Shell Programming and Scripting

extract data from a find string

Can any one please lend a helping hand here? eg. find /tough -name temp1 -print After finding the location of all temp1 files. I need to extract some data( some are multiple others are just one entry) from each of the temp file. eg Order_Error{"aaaa") Order_Error("bbba") ... (2 Replies)
Discussion started by: odogbolu98
2 Replies
Login or Register to Ask a Question