Manipulating field differences using ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulating field differences using ksh
# 1  
Old 10-08-2013
Manipulating field differences using ksh

I have a list of files that should contain the following
Quote:
35001
35002
35003
35004
35005
35006
Im trying to find the items of interest that are missing from each file and create a csv.

Code:
cat *.txt | while read file
do
grep 3500[1-6] file | tr '\012' ','
done


My problem is this possible output

one.txt 35001,35002,35005,35006
two.txt 35002,35003,35004,35005,35006
three.txt 35001,35002, 35003,35004,35005,35006
four.txt 35001,35006

What Im after is
one.txt 35001,35002,,,35005,35006
two.txt ,35002,35003,35004,35005,35006
three.txt 35001,35002, 35003,35004,35005,35006
four.txt 35001,,,,,35006

This way, when I move it into the Microsoft environment the colums will be aligned correctly.
# 2  
Old 10-08-2013
try awk solution

Code:
$ cat test_file
one.txt 35001,35002,35005,35006
two.txt 35002,35003,35004,35005,35006
three.txt 35001,35002, 35003,35004,35005,35006
four.txt 35001,35006

Code:
$  awk -F'[ ,]' '{printf $1 " ";for(i=$2;i<=$NF;i++)printf ($0~i)?(i<$NF)? i OFS:i:OFS;printf RS}' OFS="," test_file

Resulting
Code:
one.txt 35001,35002,,,35005,35006
two.txt 35002,35003,35004,35005,35006
three.txt 35001,35002,35003,35004,35005,35006
four.txt 35001,,,,,35006


Last edited by Akshay Hegde; 10-08-2013 at 02:04 AM..
# 3  
Old 10-08-2013
Compare with field.

Code:
awk -F"," '{for(i=$1;i<=$NF;i++) {++j;if ( $j != i) { printf FS ;--j } else { printf (j==NF)?i: i FS}} printf "\n";j=0}'  filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh / AIX - Differences between lists to a text file

This seems pretty simple, but I cant figure it out. I get stumped on the simple things. I am running two commands 1) take a listing a directory of files, and filter out the doc_name (which is in a series of extracted files), and place it in a file. ls -l | awk '{print $9}' | grep... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. Shell Programming and Scripting

ksh field math

Hi, I have a text like with many rows of data like: 7a,0,1182 7a,1,1040 7b,0,483 7b,1,242 7c,0,224 7c,1,877 I need to be able to take the value of the first field (i.e. 7a) and if there are multiples, add the value of the third field, (1182 + 1040) and insert the output of all of this in... (2 Replies)
Discussion started by: scriptr2be
2 Replies

3. UNIX for Advanced & Expert Users

Dot sourcing differences in ksh, AIX vs Linux vs Solaris

Why does dot sourcing of ksh functions behave so differently between AIX, Solaris, and Linux? How can I make Linux behave the way I want in the test I show below? I have a library of interdependent functions I have developed and use in ksh in AIX. They also run in Solaris. Now I am migrating... (9 Replies)
Discussion started by: charles_n_may
9 Replies

4. Shell Programming and Scripting

awk to compare 2nd and 3rd field and print the differences

need a one liner to compare 2nd and 3rd field and print values that are not matched in 2nd field Input col 2 col 3 1.1.1.1 11.11.11.11 8.8.8.8 0.0.0.0 3.3.3.3 2.2.2.2 7.7.7.7 3.3.3.3 5.5.5.5 1.1.1.1 4.4.4.4 6.6.6.6 9.9.9.9 output 7.7.7.7 ... (12 Replies)
Discussion started by: chidori
12 Replies

5. Shell Programming and Scripting

Manipulating Filenames

Hi Folks, I'm looking for some ideas on how to change some file names. I'm pretty sure I need to use sed or awk but they still escape me. The files I have are like: VOD0615 NEW Blades R77307.pdf or VOD0615_NEW_Blades_R77307.pdf and what I want after processing is: R77307 NEW Blades.pdf ... (5 Replies)
Discussion started by: imonkey
5 Replies

6. Shell Programming and Scripting

Assign field value in a .csv file to a variable using ksh

Hi, I'm new to the scripting world... I want to know that how can I assign the the field value(that has multiple lines) of a .csv file to a variable??? Model of my .csv file : 1 Poppy 5 2 red 6 3 black 5 4 white 8 and so on,the list... (4 Replies)
Discussion started by: srim
4 Replies

7. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

8. Solaris

Manipulating TOP

I need the command top to output as: Memory: 2048M real, 1499M free, 53M swap in use, 5423M swap free on just the memory line. Instead, I have compiled the new version of top that displays as so: Memory: 2048M phys mem, 1499M free mem, 5476 total swap, 5423M swap free I read... (2 Replies)
Discussion started by: adelsin
2 Replies

9. Solaris

Manipulating File

Help...please. I have a log that contains Warning Authentication Failed: User GHDT88998HS doesn't exit: The User GHDT88998HS could not be found Mar 22, 2008 5:22:22AM com.hometel.ttm.auth.userlogin. about maybe a thousand entries failed user acct message How can I grab just the username... (2 Replies)
Discussion started by: rivendell500
2 Replies

10. BSD

OpenBSD sh and ksh differences?

Hi, I am running OpenBSD 3.7, my first attempt with this OS. I noticed that both /bin/sh and /bin/ksh are both really the pdksh. Yet each has its own manpage. I was wondering what are the differences b/w the two programs on OpenBSD. I.e., has the team configured pdksh to function one way if... (3 Replies)
Discussion started by: hadarot
3 Replies
Login or Register to Ask a Question