Output format - comparison with I/p file


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Output format - comparison with I/p file

Hi,

I have a file which contains more than 1 lakh records like following:

a. name, id, city, state, country, phone (Expected I/P file format)
name, id, city,, state, country, phone (Current I/P file format )

I want to achieve following tasks,

a, Remove the extra comma in the City field.
b, Add / Remove extra string in the id field (eg. if id is 5001 I want to add 0 in the beginning, ie, 05001 / in some case, if id is 0123 remove 0 from the beginning ie, 123.

Please advice.

Thanks and Regards,
Vel
# 2  
Use SED for doing it

Case 1 : For removing multiple comma's which are together.

sed '1,$s/,,/,/' sourcefile >> targetfile


Case 2 : I understand like this.
If the id is starting with '0' then eliminate it
If its not starting with '0' then add it.

The scenario is pretty tricky...
Lets say we have a file like this
cat test
1001,aa,bb,cc,dd
1001,aa,bb,cc,dd
1001,aa,bb,cc,dd
1001,aa,bb,cc,dd
011,aa,bb,cc,dd
011,aa,bb,cc,dd
011,aa,bb,cc,dd
011,aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,c,d

and if i run like this
sed '1,$s/^[1-9]/0/;1,$s/^0//' test

Check the output..

001,aa,bb,cc,dd
001,aa,bb,cc,dd
001,aa,bb,cc,dd
001,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,c,d

but we didnt need this..
We will have to distinguish between them..
so use this command.
sed '1,$s/^[1-9]/-0&/;1,$s/^0//' test >> test1
cat test1
output
======
-01001,aa,bb,cc,dd
-01001,aa,bb,cc,dd
-01001,aa,bb,cc,dd
-01001,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
aa,bb,cc,,dd
aa,bb,cc,,dd
aa,bb,cc,,dd
aa,bb,cc,,dd
aa,bb,c,d

Now u just have to eliminate the "-"
sed 's/^-//g' test1 >> test2
cat test2
output
=====
01001,aa,bb,cc,dd
01001,aa,bb,cc,dd
01001,aa,bb,cc,dd
01001,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,c,d

Hope i have made this clear.
Let me know if any.....
Login or Register for Dates, Times and to Reply

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

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with printing output format from a file

Hi, I need help in printing data in below format from file extensions with .dml, i have listed details below file name is test_temp.dml, location in /home/users/test01/test_temp.dml file content: sample_type= record decimal(",") test_type; date("DD-MM-YYYY")(",") test_date... (2 Replies)
Discussion started by: AAHinka
2 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Shell Programming and Scripting

File comparison of different format

i have file as FileD funny mou1 funny mou2 raspe mou4 damn mou1 this file is a csv with /t. i want to find all values with the first column of this file in fileB and then check for in that line if the second column vvalues are present or not . for eg... (4 Replies)
Discussion started by: rajniman
4 Replies

5. Shell Programming and Scripting

awk file comparison, x lines after matching as output

Hello, I couldn't find anything on the Forum that would help me to solve this problem. Could any body help me process below data using awk? I have got two files: file1: Worker1: Thomas Position: Manager Department: Sales Salary: $5,000 Worker2: Jason Position: ... (5 Replies)
Discussion started by: killerbee
5 Replies

6. Shell Programming and Scripting

format a file to this output

hi i need some help over here.. please help i have a log file as per below --------------------------------------------------------------------------------------------------------- JOB START DATE : 20110510204513 JOB ID : us2cap3ds9... (6 Replies)
Discussion started by: sitaldip
6 Replies

7. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

8. Shell Programming and Scripting

format file output

Hi, I am trying to put a script together that allows for a command to be executed and then the output goes to a .html file. I am running the script on HPUX. I run: /var/fl/user/lmutil lmstat a c license_lic.dat > /web/results.html This saves the command to a .html file but the text is... (1 Reply)
Discussion started by: zerbitated
1 Replies

9. Shell Programming and Scripting

format the output from a file

hi , i need to format the output which is availble in a file file output is Following are the Process_Scheduler Domains running in the server Ram-pc VPORCL Following are the Application Server domains running in the server Ram-pc VPORCL01 VPORCL02 these value VPORCL,VPORCL01...... (5 Replies)
Discussion started by: becksram123
5 Replies

10. Shell Programming and Scripting

Format the output of file

hello all Script and example of file #!/bin/sh #sh gdata.sh /users/testsuite/db/appl/ DATE=`date '+20%y-%m-%d'` echo $DATE for i in ${1}/$DATE/* ; do find $i -name daily -prune -o -name run.log -print -exec grep -c ! {} \; done > test.log. The test.log contains output like this ... (9 Replies)
Discussion started by: getdpg
9 Replies

Featured Tech Videos