Read from Multiple character delimited flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read from Multiple character delimited flat file
# 1  
Old 12-09-2011
Read from Multiple character delimited flat file

Hello Guys

I have a multiple character delimited flat file "|~|". when I tried to read the data the "|" character also coming

Example
I/P file
Code:
 
9882590|~|20111207|~|K03501000063005574033961|~|K|~|

Command to get the second column I used

Code:
 
 awk -F"|~|" ' {print $2}'  ff_CGS_0005_CGS300.dat

The result I am having

Code:
 
|20111207|

Can you please correct me to get the value without the pipe character
Thnx a lot!
# 2  
Old 12-09-2011
Code:
perl -F"\|~\|" -lane 'print "$F[1]"' ff_CGS_0005_CGS300.dat

# 3  
Old 12-09-2011
Hi,

You could also use

Code:
$echo "9882590|~|20111207|~|K03501000063005574033961|~|K|~|" | awk -v FS="|" '{print $3}'
20111207

Or you could change |~| to | then pass on to awk.

Code:
$echo "9882590|~|20111207|~|K03501000063005574033961|~|K|~|" | sed 's/|~|/|/g' | awk -v FS="|" '{print $2}'
20111207

After more searching.
Code:
$echo "9882590|~|20111207|~|K03501000063005574033961|~|K|~|" | awk -v FS="[|~]+" '{print $2}'
20111207


Last edited by ni2; 12-09-2011 at 03:39 AM.. Reason: Did more searching.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove first NULL Character in Flat File

We have a flat file with below data : ^@^@^@^@00000305^@^@^@^@^@^@430^@430^@^@^@^@^@^@^@^@^@09079989530As we can see ^@ is Null character in this file I want to remove only the first few null characters before string 00000305 How can we do that, any idea. I want a new file without first few... (5 Replies)
Discussion started by: simpltyansh
5 Replies

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

3. Shell Programming and Scripting

awk read one delimited file, search another delimited file

Hello folks, I have another doozy. I have two files. The first file has four fields in it. These four fields map to different locations in my second file. What I want to do is read the master file (file 2 - 23 fields) and compare each line against each record in file 1. If I get a match in all four... (4 Replies)
Discussion started by: dagamier
4 Replies

4. UNIX for Dummies Questions & Answers

Flat File - Comma Delimited

I have a flat file whose contents are comma delimited and there are 84 columns in total, so everytime I try to view the contents, things get over lapped it becomes diffcult to read through the result set. Is there a command / what would be the best way...if I want to view the results alligned... (4 Replies)
Discussion started by: priya33184
4 Replies

5. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

6. Shell Programming and Scripting

How to read the first column in a flat file with ~ as delimiter

I have one flat file like below id1~col~batch1 id2~col2~batch2 id3~col3~batch3 I need to read the first column one by one and I need to write one db2 query based on that column1 Like for (i=0;i<=10;i++) do insert into table column (con_id) values (select column from table where... (4 Replies)
Discussion started by: siri_886
4 Replies

7. Shell Programming and Scripting

how to read fixed length flat file....

Hi Gurus, Thanks in advance... I am new to writing shell scripting and help me out reading a flat file with fixed length. I have a fixed length flat file with storename(lenth 6) , emailaddress(lenth 15), location(10). There is NO delimiters in that file. Like the following str00001.txt... (2 Replies)
Discussion started by: willywilly
2 Replies

8. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

9. Shell Programming and Scripting

How to read lines from a flat file

i have some commands written line by line in one flat file i have to read each linefrom this file(file name passed as parameter) and then i have to execute this How can i do it? (2 Replies)
Discussion started by: bihani4u
2 Replies

10. Shell Programming and Scripting

Sorting a flat file based on multiple colums(using character position)

Hi, I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting. I understand that there is a previous... (8 Replies)
Discussion started by: cucubird
8 Replies
Login or Register to Ask a Question