substringing non field non seperated text


 
Thread Tools Search this Thread
Operating Systems AIX substringing non field non seperated text
# 1  
Old 04-29-2009
substringing non field non seperated text

In optimizing and bulletproofing the scripts running on my client's AIX 4.2 (Korn shell), I will need a way to examine and/or extract informations from non field non seperated text to be used for several purposes.

How could I do the same for these situations :

ex-1:

"00000"+"1" => "00001" (5 last char)
"00000" +"12" => "00012" (5 last char)


ex-2:
"aaaaa12345aaaaa@ => "12345" (extract that part where position is known)
"aaaaa12345aaaaa@ => "12345" (extract that part where position is unknown)


ex-3:
multi-line rec (variable format + possible spaces at beginning of line)
adfadasdf(aaaa),adkalsd,
klajdf,hklajhklajh(akdjakjflkajmakfaklj),
ifuioioa(usdoiau(akljsdlkajdh),alkdjfhkajsdh)

into
adfadasdf(aaaa),adkalsd,klajdf,hklajhklajh(akdjakjflkajmakfaklj),ifuioioa(usdoiau(akljsdlkajdh),alkd jfhkajsdh)

multi-line record contains any combinations/amount of fields and any combination/amount of separators.
# 2  
Old 05-01-2009
The ksh93 has a substring function you could use, but AIX 4.2 uses a ksh88 as the default shell and it is probably more robust to rely on that.

In this case you could use the variable expansion feature of the ksh to extract the strings:

${var%%???} gives everything except the last 3 characters of variable $var
${var##???} gives everything except the first 3 characters of variable $var
etc.

It is possible to nest these expressions to get a substring-like functionality. Have a look in a ksh book to find out more about variable expansion.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Seperated a Column from 'ESC' Character seperated file

Hi Experts I have an escape seperated fields in the unix file. And in the below format file I need to extract the first column. Please help its urgent. cat -v op.dat | head 24397028^ I want to extract the file in below format ( with only first column ) 24397028 2439707 thanks. ... (6 Replies)
Discussion started by: neha_suri06
6 Replies

2. Shell Programming and Scripting

awk to parse field and include the text of 1 pipe in field 4

I am trying to parse the input in awk to include the |gc= in $4 but am not able to. The below is close: awk so far: awk '{sub(/\|]+]++/, ""); print }' input.txt Input chr1 955543 955763 AGRN-6|pr=2|gc=75 0 + chr1 957571 957852 AGRN-7|pr=3|gc=61.2 0 + chr1 970621 ... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Read text between regexps and write into files based on a field in the text

Hi, I have a huge file that has data something like shown below: huge_file.txt start regexp Name=Name1 Title=Analyst Address=Address1 Department=Finance end regexp some text some text start regexp Name=Name2 Title=Controller Address=Address2 Department=Finance end regexp (7 Replies)
Discussion started by: r3d3
7 Replies

4. Shell Programming and Scripting

Inserting some text if a field in the last column changes

Hi, I have a file which looks like this: A 01 00 B 02 00 C 04 00 D 00 01 E 01 01 F 02 01 G 01 04 H 02 04 I want to insert some text if the field if the last column changes. It should look like this: Value 00 A 01 00 B 02 00 C 04 00 Value 01 (6 Replies)
Discussion started by: wenclu
6 Replies

5. UNIX for Dummies Questions & Answers

Need help removing leading spaces from one field in comma seperated file

Using awk or sed, I'd like to remove leading spaces after a comma and before a right justified number in field 6. Sounds simple but I can't find a solution. Each field's formatting must stay intact. Input: 40,123456-02,160,05/24/2012,02/13/1977, 10699.15,0 Output:... (5 Replies)
Discussion started by: Scottie1954
5 Replies

6. Shell Programming and Scripting

Awk Search text string in field, not all in field.

Hello, I am using awk to match text in a tab separated field and am able to do so when matching the exact word. My problem is that I would like to match any sequence of text in the tab-separated field without having to match it all. Any help will be appreciated. Please see the code below. awk... (3 Replies)
Discussion started by: rocket_dog
3 Replies

7. Shell Programming and Scripting

Convert comma seperated file to line seperated.

Hi, I have data like this. 1,2,3,4 Output required: 1 2 3 4 I am trying to use tr function but getting error. Help is appreciated. (6 Replies)
Discussion started by: pinnacle
6 Replies

8. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

9. Web Development

Dynamic text field

Hi I have a webpage where I have a dropdown box and depending on the selection I would like to populate a text field . Preferably with JavaScript (2 Replies)
Discussion started by: bombcan
2 Replies

10. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies
Login or Register to Ask a Question