Visit The New, Modern Unix Linux Community


File Handling in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File Handling in UNIX
# 1  
File Handling in UNIX

Hi all,

I have a requirement here where I am dealing with a dynamic file. Each record in the file can contain anywhere between 1(min) to 42(max) Reject codes. For example I may have one record in the file having 3 reject codes and another record having 5 reject codes. The reject codes will be preceded by a field Reject count which would indicate the number of reject codes present in the record. For example

|FA4|FB56|FB55|FB32|FB21|.....
Here FA corresponds to the field that contains the reject count(4) in this case. And there are four Reject codes(56,55,32 and 21) that follow it.

Now my actual issue is that since there can be a maximum of 42 Reject Codes, we have 42 reject code fields in the target table. Hence I would need a code in UNIX that would check for the count of reject codes line by line(using the reject count column) for each record and depending on its value x(say 4 as in the above scenario) insert 'n' pipeline delimiters(where n=42-x) to the record( 38 in this case) after the the last reject code field(after FB21 in this case) to bring the total count upto 42. This way the first 4 reject code fields in the target table would be populated with values from the file while NULL would be populated for the remaining reject code fields in the target table.This code has to be dynamic in line with the varying reject code counts appearing in the file. Any inputs on this will be greatly applauded..Thanks in advance
# 2  
Try,

Code:
$ perl -F'\|' -anle '$n=substr($F[1],2);print $_."|"x(42-$n)'


Last edited by agn; 02-15-2010 at 06:48 AM.. Reason: code tags
# 3  
File Handling

Hi,

Thanks a lot for your reply..But the code aint working. I tried the following command

perl -F '\|' -anle '$n=substr($F[1],2);print $_."|"x(42-$n)' Rej3.txt
Error: Can't open perl script "\|": A file or directory in the path name does not exist.


Here Rej3.txt is the name of the file. One more thing the FA* field(Reject count field ) is present as the seventh field in each record.

Also it will be great if you explain the meaning of each and every part in the command syntax. Thanks
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #201
Difficulty: Easy
Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX file handling issue

I have a huge file semicolon( ; ) separated records are Pipe(|) delimited. e.g abc;def;ghi|jkl;mno;pqr|123;456;789 I need to replace the 50th field(semicolon separated) of each record with 9006. The 50th field can have no value e.g. ;; Can someone help me with the appropriate command. (3 Replies)
Discussion started by: Gurkamal83
3 Replies

2. Programming

Please help:program hang stuck there signal handling on POSIX Message Queue UNIX C programming

in a single main() function,so need signal handling. Use Posix Message Queue IPC mechanism , can ignore the priority and other linked list message,to implement the scenario: client:Knock Knock server:who's there client: Eric Server:Eric,Welcome. client:exit all process terminated ... (1 Reply)
Discussion started by: ouou
1 Replies

3. Shell Programming and Scripting

UNIX File handling -Issue in reading a file

I have been doing automation of daily check activity for a server, i have been using sqls to retrive the data and while loop for reading the data from the file for several activities. BUT i got a show stopper the below one.. where the data is getting store in $temp_file, but not being read by while... (1 Reply)
Discussion started by: KuldeepSinghTCS
1 Replies

4. Shell Programming and Scripting

Error handling in Unix shell scripting

Hello, I have written a shell script and suppose there is any error in the script. How i can do exception handling in shell script.for example i have below code sqlplus -s <<uid>>/<<pwd>>@<<$ORACLE_SID>> <<EOF > 1_pid1.log set pagesize 0 set feedback off set heading off set linesize 200... (1 Reply)
Discussion started by: rksingh003
1 Replies

5. UNIX for Dummies Questions & Answers

Socket Handling Differences Between Linux & Unix?

Sorry if this is a stupid question! I have been developing a Java application that I am deploying on both Unix and Linux servers, which uses lots of socket handling. When the server side connection is dropped by the server un-gracefully I have been seeing close_waits and null connections. ... (0 Replies)
Discussion started by: Vinnie
0 Replies

6. Shell Programming and Scripting

Help needed in switch case handling in UNIX

Hi, In below code, i am expecting the output has Bye Bye But i am getting has Bye Hi Code: #!/usr/bin/bash var="Hi" cat txt.txt | while read var1 do next="Bye" case $var in Hi) (1 Reply)
Discussion started by: Balamani
1 Replies

7. Shell Programming and Scripting

File handling, getopts command in unix

I need to create a shell script having the menu with few options such as 1. Listing 2. Change permissions 3. Modify Contents 4. Delete Files 5. Exit 1. For 1. Listing: Display a special listing of files showing their date of modification and access time (side by side) along with their... (2 Replies)
Discussion started by: bab123
2 Replies

8. UNIX for Dummies Questions & Answers

VARIABLE HANDLING in UNIX

Hi All, :confused: can anyone throw some light on variable handling in UNIX script?? I want to know about the local variables we declare inside the UNIX script. e.g. i=10 OR cat file1 | while read line do echo $line done etc. Does UNIX have any data types Can some one... (1 Reply)
Discussion started by: VENC22
1 Replies

9. UNIX for Dummies Questions & Answers

File handling in UNIX

Hi All, I want to read a file in UNIX line by line. Can u suggest me any command for this? (4 Replies)
Discussion started by: VENC22
4 Replies

10. Shell Programming and Scripting

handling spaces in unix

I am testing a ksh script for email. In the script I receive several parameters. One of them is a subject. The subject may contain spaces. Ex. Test this. When I am running the script on telnet to test, how should the syntax at the command line be written. I have this: ksh ResendE.sh '001111'... (2 Replies)
Discussion started by: supercbw
2 Replies

Featured Tech Videos