Using AWK to parse a delimited field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using AWK to parse a delimited field
# 8  
Old 06-18-2010
Quote:
Originally Posted by Franklin52
@Scrutinizer, it doesn't give the right output on a HP-UX system:
Code:
$ s="fat#bob"
$ echo ${s%#*}
fat#bob
$ echo ${s#*#}
fat#bob

Regards
Which version of HP-UX and which shell are you using?

Code:
$ s="fat#bob";echo ${s%#*};echo ${s#*#}
fat
bob
$ uname -sr
HP-UX B.11.11
$ ps -p$$
   PID TTY       TIME COMMAND
 23283 pts/ta    0:00 ksh
$

Consider that the above mentioned parameter expansion is required by SUS/POSIX, so on your system you may need to use a POSIX compliant shell.

---------- Post updated at 12:37 PM ---------- Previous update was at 12:31 PM ----------

I see that on HP-UX B.11.11 /usr/bin/sh(a M-ksh88f) is labeled as POSIX shell.

I dont know why it doesn't support the parameter expansion mentioned above.
# 9  
Old 06-18-2010
Quote:
Originally Posted by radoulov
Which version of HP-UX and which shell are you using?

Code:
$ s="fat#bob";echo ${s%#*};echo ${s#*#}
fat
bob
$ uname -sr
HP-UX B.11.11
$ ps -p$$
   PID TTY       TIME COMMAND
 23283 pts/ta    0:00 ksh
$

Consider that the above mentioned parameter expansion is required by SUS/POSIX, so on your system you may need to use a POSIX compliant shell.

---------- Post updated at 12:37 PM ---------- Previous update was at 12:31 PM ----------

I see that on HP-UX B.11.11 /usr/bin/sh is defined as POSIX shell.

I dont know why it doesn't support the parameter expansion mentioned above.

---------- Post updated at 12:37 PM ---------- Previous update was at 12:37 PM ----------

I see that on HP-UX B.11.11 /usr/bin/sh is defined as POSIX shell.

I dont know why it doesn't support the parameter expansion mentioned above.
The version on my system is:
Code:
uname -sr
HP-UX B.11.00

# 10  
Old 06-18-2010
Yes, HP-UX's /usr/bin/sh is a ksh Version M-11/16/88f and it doesn't support that parameter expansion.

On those systems /usr/bin/ksh, which is actually ksh88c, supports it.
# 11  
Old 06-18-2010
Hi Franklin, your version seems a tad old (Support for HP-UX 11.0 (B.11.00) ended December 2006.). Do you have to escape the # to get it to work? Perhaps the have been bug fixes?
# 12  
Old 06-18-2010
Quote:
Originally Posted by Scrutinizer
Hi Franklin, your version seems a tad old (Support for HP-UX 11.0 (B.11.00) ended December 2006.). Do you have to escape the # to get it to work? Perhaps the have been bug fixes?
Right, it works well if I escape the # like:
Code:
s="fat#bob"
echo ${s%\#*}
echo ${s#*\#}

Regards
# 13  
Old 06-18-2010
Quote:
Originally Posted by Franklin52
Right, it works well if I escape the # [...]
OK Smilie
So ksh Version M-11/16/88f supports that parameter expansion, but it has some bugs (or this behavior is documented).
# 14  
Old 06-18-2010
Thanks for all the help everyone! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

2. UNIX for Beginners Questions & Answers

awk to parse current and next row in tab-delimited file

Hi there, I would like to use awk to reformat a tab-delimited file containing three columns as follows: Data file: sample 1 173 sample 269 530 sample 687 733 sample 1699 1779 Desired output file: sample 174..265, 531..686, 734..1698 I need the value... (5 Replies)
Discussion started by: emiley
5 Replies

3. 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

4. Shell Programming and Scripting

awk Parse And Create Multiple Files Based on Field Value

Hello: I am working parsing a large input file which will be broken down into multiples based on the second field in the file, in this case: STORE. The idea is to create each file with the corresponding store number, for example: Report_$STORENUM_$DATETIMESTAMP , and obtaining the... (7 Replies)
Discussion started by: ec012
7 Replies

5. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

6. UNIX for Advanced & Expert Users

Parse (delimited string) key-value pairs in a column into separate lines

Hi experts, e.g. i/p data looks like 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified|| o/p data should like - row1: 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified ... (1 Reply)
Discussion started by: sumoka
1 Replies

7. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

8. Shell Programming and Scripting

Use awk or sed to parse delimited string

Hi I am trying to figure out the best way to search a long log file and print out certain information. For example if I had a line in a log file delimited by ampersand first_name=mike&last_name=smith&zip_code=55555&phone=555-5555&state=ma&city=boston and I only wanted to search for and... (3 Replies)
Discussion started by: mstefaniak
3 Replies

9. Shell Programming and Scripting

how to parse with awk (using different fields), then group by a field?

When parsing multiple fields in a file using AWK, how do you group by one of the fields and parse by delimiters? to clarify If a file had tom | 223-2222-4444 , randofield ivan | 123-2422-4444 , random filed ... | and , are the delimiters ... How would you group by the social security... (4 Replies)
Discussion started by: Josef_Stalin
4 Replies

10. Shell Programming and Scripting

Parse comma delimited and optionally quotes dimilited file

Hi, Can you please help me? How to Parse a comma delimited and optionally quotes dimilited file? sample.dat ---------- "I",+2007,"SANDA, 20, MARTIN PLACE","SANDA 20MARTIN" "D",+2008,"RANDA, 22, MARTIN PLACE","RANDA 22MARTIN" Thank you. Ram (8 Replies)
Discussion started by: vramana2003
8 Replies
Login or Register to Ask a Question