Scripting to fix the issue in UNIX file having delimiter "|"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting to fix the issue in UNIX file having delimiter "|"
# 1  
Old 01-21-2013
Linux Scripting to fix the issue in UNIX file having delimiter "|"

hello All,

I am new user to shell scripting, kindly advise on the below?

I have a file where i have gaps & the delimiter falls in next line and new line is also created , plz see the example :employee.txt

Now the issue here is , i wan to write a script , where i can use "|" to get the contents in line , plz let me know if this is possible to write script as per all the line should not fall to the next lineSmilie

Code:
 
cat employee.txt 
2344| walter|richey lenord| engineer | 4567
2341| terry|richey lenord
 
|engineer | 4567
2344| salter|leopord cafe | treasure | 4988
2144| jacob 
|kistern manufac| hitlor | 4563
2644| walter|richey lenord | engineer 
| 4167
2804| walter
|richey lenord | engineer | 4767

Regards,
Sunny

Last edited by Scott; 01-21-2013 at 11:13 AM.. Reason: Code tags; Moved to correct forum
# 2  
Old 01-21-2013
Code:
while IFS="|" read A B C D E F G
do
...
done < inputfile

# 3  
Old 01-21-2013
Linux

The code did not work say's command not found on line 3


Regards,
Sunny
# 4  
Old 01-21-2013
You don't put ... literally.

You replace it with whatever you want.

I don't understand what you mean by 'fall to the next line' however.
# 5  
Old 01-21-2013
Linux

when i receive the file through another system the line should read as :

Where you have the text "|enon engineer | 4567" pushed up on the previous line , like the correct order.

Code:
 
Correct order :
2344| walter|richey lenord| engineer | 4567
 
 
Incorrect order :
2341| terry|richey lenord
 
|engineer | 4567
 
2344| salter|leopord cafe | treasure | 4988
2144| jacob


Last edited by Scott; 01-21-2013 at 12:33 PM.. Reason: Please use code tags
# 6  
Old 01-21-2013
Run this program to fix your file:
Code:
awk '/\|/' employee.txt | sed '/[^0-9]$/{h;N;s/\n//;}'

and read using script provided by Corona688
# 7  
Old 01-21-2013
To repair try:
Code:
awk -F\| '{while(NF<5||$NF==""){getline p; $0=$0 p}}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Substituting comma "," for dot "." in a specific column when comma"," is a delimiter

Hi, I'm dealing with an issue and losing a lot of hours figuring out how i would solve this. I have an input file which looks like this: ('BLABLA +200-GRS','Serviço ','TarifaçãoServiço','wap.bla.us.0000000121',2985,0,55,' de conversão em escada','Dia','Domingos') ('BLABLA +200-GRR','Serviço... (6 Replies)
Discussion started by: poliver
6 Replies

4. Shell Programming and Scripting

""Help Me!""Beginner awk learning issue

Hi All, I have just now started learning awk from the source - Awk - A Tutorial and Introduction - by Bruce Barnett and the bad part is that I am stuck on the very first example for running the awk script. The script is as - #!/bin/sh # Linux users have to change $8 to $9 awk ' BEGIN ... (6 Replies)
Discussion started by: csrohit
6 Replies

5. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Advanced & Expert Users

fsck.gfs2 outputs "RG recovery impossible; I can't fix this file system"

I have a CentOS release 5.2 (Final)host running kernel 2.6.18-92.el5 with at raid 10 that had two mirrored drives fail. The drives were re-inserted and now the raid shows healthy (for now). I tried to mount but got an Input/output error. I then attempted a fsck: fsck.gfs2 -y /dev/vg_01/uss_vol... (0 Replies)
Discussion started by: king_hippo
0 Replies

8. UNIX for Dummies Questions & Answers

Encoding Problem while using "|" (PIPE) as delimiter from Mainframe to Unix

We are facing a problem with PIPE (|) as a delimiter in one of our FTP flat files. We are constructing a Flat file in IBM-AIX and this contains various strings delimted by PIPE Symbol and then FTPing this to a Mainframe System The Mainframe program simply recieves this and FTPs the same... (1 Reply)
Discussion started by: seshendra
1 Replies

9. Shell Programming and Scripting

Scripting multiple file "puts" in sFTP...

I need to send multiple files to a remote server via sFTP. I had everything set up to connect and send a single file automatically using a batch file and key authentication. Recently, however, the process has changed and we now need to send multiple files, one at a time, pausing for up to ten... (5 Replies)
Discussion started by: Cbish68
5 Replies

10. UNIX for Advanced & Expert Users

Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour

Hi, We have a DEC Alpha 4100 Server with OSF1 Digital Unix 4.0. Can any one tell me, if there are any commands on this Unix which are equivalent to "top" and "sar" on HP-UX or Sun Solaris ? I am particularly interested in knowing the CPU Load, what process is running on which CPU, etc. ... (1 Reply)
Discussion started by: sameerdes
1 Replies
Login or Register to Ask a Question