how to extract a tilde delimited file in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to extract a tilde delimited file in unix
# 8  
Old 03-02-2007
try this code:
Code:
awk '
{
while ( $0 ~ "  " )
{
sub("  ", " ", $0)
}  print }' test |  sed "s/ /\~/g;" >result1
awk '
{
while ( $0 ~ "  " )
{
sub("  ", " ", $0)
}  print }' result1 |  sed "s/ /\~/g;" |sed "s/\(^.*\~..\~.*\)\(\~..\~\)\(.*\)\(\~.....$\)/\3/g" >result2
sed 's/~/ /g' result2>result3
count=0
while read line; do
count=`echo $count+1|bc`
export value=${count}P
sed -n "$value" result2 |read val
sed -n "$value" result1 | read res1
echo $res1 | sed "s/$val/$line/g"
done <result3

Well, Forum members, This might be a bit clumsy but thats the best i could get. If there is a better way please let me know.
# 9  
Old 03-05-2007
even if there are mulitple spaces in between fields i just want one tilde
# 10  
Old 03-05-2007
Code:
sed 's/  */~/g' file

Not the two whitespace between / and *
# 11  
Old 03-05-2007
Quote:
Originally Posted by matrixmadhan
Code:
sed 's/  */~/g' file

Not the two whitespace between / and *
This will match with a single space as well
*=0 or more
# 12  
Old 03-05-2007
Quote:
Originally Posted by trichyselva
i have a file in unix in which datas are like this

Code:
07 01  abc data entry                  Z3 data entry ASSISTANT          Z3 39
08 01  POD peadiatrist                 Z4 POD PeDIATRY                     Z4 67
    01      operator specialist         00 operator  UNSPECIFIED          A0 00
    02      OLD NPA SPECIALTY      01 GP  GENERAL PRACTICE          C5 01

i want the datas to be tilde delimited as
07~01~abc~data entry~Z3~data entry ASSISTANT~Z3~39
~01~~operator specialist~00~operator UNSPECIFIED~A0~00

can anybody help me on this in writing code for this
I'd want more specifications before I could whip up a good script/program. For example, I see it could be lined up. If everything's fixed width, you could just use a cut command to break each line up into manageable bits and then just output the tilde's. Are their always the same number of fields? Are fields 1, 2, 5, 7, and 8 always two digit fields? Can other fields besides 1 and 3 be blank?

I'd do something like read the entire line into an array. I'd check each of the array elements to see if they match rules (like the two digit fields) and put everything in the right place. The only wrench is that third field and what might be in it.

So the basic answer here is, insufficient specifications. Sorry Smilie

Carl
# 13  
Old 03-06-2007
Quote:
Originally Posted by sb008
This will match with a single space as well
*=0 or more

This was the requirement note from the OP
Quote:
even if there are mulitple spaces in between fields i just want one tilde
Thats is the reason I had

<whitespace><whitespace>*

to match both single and multiple whitespaces
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle table extract: all columns are not converting into pipe delimited in flat file

Hi All, I am writing a shell script to extract oracle table into a pipe dilemited flat file. Below is my code and I have attached two files that I have abled to generate so far. 1. Table.txt ==> database extract file 2. flat.txt ==> pipe delimited after some manipulation of the original db... (5 Replies)
Discussion started by: express14
5 Replies

2. UNIX for Dummies Questions & Answers

Need help with tab delimited file in unix

Hi, I need urgent help with a tab delimited file I am working on. This is the file : TTTT|YYYYYYY|jargon-journal|MP0000000UID||"j1, j2, j3" I need th following output: TTTT|YYYYYYY|jargon-journal|MP0000000UID||ji TTTT|YYYYYYY|jargon-journal|MP0000000UID||j2... (8 Replies)
Discussion started by: rayarnab
8 Replies

3. Shell Programming and Scripting

Extract a nth field from a comma delimited file

Hi, In my file (which is "," delimited and text qualifier is "), I have to extract a particualr field. file1: 1,"aa,b",4 expected is the 2nd field: aa,b I tried the basic cut -d "," -f 2 file 1, this gave me aa alone instead aa,b. A small hint ot help on this will be very... (5 Replies)
Discussion started by: machomaddy
5 Replies

4. Shell Programming and Scripting

Extract second column tab delimited file

I have a file which looks like this: 73450 articles and news developmental psychology 2006-03-30 16:22:40 1 http://www.usnews.com 73450 articles and news developmental psychology 2006-03-30 16:22:40 2 http://www.apa.org 73450 articles and news developmental psychology 2006-03-30... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

bash extract all occurences delimited from <name> and </name> tags from an xml file

I need to extract all text delimited from <name> and </name> tags from an xml file, but not only first occurence. I need to extract all occurences. I've tried with this command: awk -F"<name>|</name>" 'NF>2{print $2}' but it give only first occurence. How can i modify it? (18 Replies)
Discussion started by: ingalex
18 Replies

6. Shell Programming and Scripting

Extract value from delimited file base on white list

I would like to use a variable to store the IDs that I would like to extract. I would like to extract a list of values of the IDs from a delimited string. Using bash here. file format would be id1=we1;id2=er2;id3=rt3;id4=yu4 The number of fields and records is not fixed. There could be... (2 Replies)
Discussion started by: milo7
2 Replies

7. UNIX for Dummies Questions & Answers

Extract records by column value - file non-delimited

the data in my file is has no delimiters. it looks like this: H52082320024740010PH333200612290000930 0.0020080131 D5208232002474000120070306200703060580T1502 TT 1.00 H52082320029180003PH333200702150001 30 100.0020080205 D5208232002918000120070726200707260580T1502 ... (3 Replies)
Discussion started by: jclanc8
3 Replies

8. Shell Programming and Scripting

Delete Duplicate records from a tilde delimited file

Hi All, I want to delete duplicate records from a tilde delimited file. Criteria is considering the first 2 fields, the combination of which has to be unique, below is a sample of records in the input file 1620000010338~2446694087~0~20061130220000~A00BCC1CT... (5 Replies)
Discussion started by: irshadm
5 Replies

9. Shell Programming and Scripting

replacing commas with tilde in csv file.

hello all, i have a comma delimited file. i want to replace the commas in the file with the tilde symbol using sed. how can i do this? thanks. (4 Replies)
Discussion started by: femig
4 Replies

10. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies
Login or Register to Ask a Question