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
# 1  
Old 03-02-2007
how to extract a tilde delimited file in unix

i have a file in unix in which datas are like this

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
# 2  
Old 03-02-2007
Code:
sed 's/ /~/g' file

else

Code:
awk '{ for(i=1; i<=NF; i++) { if( i==NF ) { printf "%s", $i } else { printf "%s~", $i } } printf "\n" }' file


Last edited by matrixmadhan; 03-02-2007 at 05:02 AM.. Reason: alternative solution
# 3  
Old 03-02-2007
Code:
tr ' ' '~' < file

# 4  
Old 03-02-2007
Code:
awk ' gsub(" ","~",$0) ' file

or
In ksh
Code:
awk ' { OFS="~" ; $1=$1; print } ' file

or
In bash
Code:
while read str
do
   echo ${str// /~}
done < file

# 5  
Old 03-02-2007
don't think they produce the desired output.
not all blank spaces need to be converted to tildes, as shown in the sample output OP provided
# 6  
Old 03-02-2007
Quote:
Originally Posted by ghostdog74
don't think they produce the desired output.
not all blank spaces need to be converted to tildes, as shown in the sample output OP provided
You are right.

trichyselva,
Can you be more specific on how do you want to add tilde?
# 7  
Old 03-02-2007
try this:

Code:
awk '{
while ( $0 ~ "  " )
{
sub("  ", " ", $0)
}  print }' test |  sed 's/ /~/g;'

In which fields do you want to avoid the ~ sign???

Last edited by ahmedwaseem2000; 03-02-2007 at 08:01 AM..
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