Manipulation of file data with UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulation of file data with UNIX
# 1  
Old 02-13-2013
Manipulation of file data with UNIX

Hello , How all doing today.. I have a little doubt in Unix

Last edited by adisky123; 02-14-2013 at 01:11 AM..
# 2  
Old 02-13-2013
What have you done so far to resolve your "doubt"?
# 3  
Old 02-13-2013
Just developing the thought process, can be wrong
Code:
i=0
cat file | while read line
do 
a=`echo $line | cut -d':' -f1`
b=`echo $line | cut -d':' -f2`

if [ i <= 0] then
    echo $a
    
    i++
fi
if [ i >=0 ] then 
     Then Compare $a with 1st field of next line if same the concatenate the second field
    fi

# 4  
Old 02-13-2013
Code:
awk -F: '$1!=f1 {printf("%s%s",(FNR==1)?"":ORS,$0);f1=$1;next}{printf(" %s", $2)}END{printf ORS}' myFile

# 5  
Old 02-13-2013
Thanks for your support. Its just an idea
Can't it be done with and array (like hashing)
# 6  
Old 02-13-2013
Quote:
Originally Posted by adisky123
Thanks for your support. Its just an idea
Can't it be done with and array (like hashing)
I don't know what you mean, but you can definitely try.....
# 7  
Old 02-13-2013
I took the liberty to modify your script:
Code:
#!/bin/bash

i=0
while read line
do

a=`echo $line | cut -d':' -f1`
b=`echo $line | cut -d':' -f2`

if [  -z "${p_a}" ] || [  -z "${p_b}" ]
then
        printf "${a}:${b} "
elif [ "${a}" == "${p_a}" ]
then
        printf "${b} "
elif [ "${a}" != "${p_a}" ]
then
        printf "\n${a}:${b} "
fi

p_a=${a}
p_b=${b}

done < file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Manipulation - UNIX script

Hi, I have a file about 100 lines. Each line is about 2000 characters (each line is fixed length). In middle of each line is following constant value 0000040029892586 Now, I want to go through each line and increment by 1. So, line 1 will have 586 line 2 will have 587, line 3 will have... (4 Replies)
Discussion started by: jakSun8
4 Replies

2. Shell Programming and Scripting

Data Manipulation on a .csv file

Hallo Friends, I need you help. My file has 5000 or so lines and currently looks like below(sample). Service Type,Origin,Destination,Rate Per Minute,Minimum Charge,Time Based Rate,Time Based From Day,Time Based To Day,Time Based From Time,Time Based To Time,Destination Prefix List,, VoIS... (3 Replies)
Discussion started by: kekanap
3 Replies

3. Shell Programming and Scripting

Populating File data with custom manipulation on file names

Hi, I am confused how to proceed firther please find the problem below: Input Files: DCIA_GEOG_DATA_OCEAN.TXT DCIA_GEOG_DATA_MCRO.TXT DCIA_GEOG_DATA_CVAS.TXT DCIA_GEOG_DATA_MCR.TXT Output File Name: MMA_RFC_GEOG_NAM_DIM_LOD.txt Sample Record(DCIA_GEOG_DATA_OCEAN.TXT):(Layout same for... (4 Replies)
Discussion started by: Arun Mishra
4 Replies

4. AIX

Unix File name manipulation

I need a script that will raname the following file names that beging with 08078* in unix as follows: Rename 08078-08201103-H00044-CA.835 as follows: 08078-110820-H000440CA.835 Bascially it will do this: 1) Keep the first 6 positons. 2) Move the yr from the file name to be the... (4 Replies)
Discussion started by: mrn6430
4 Replies

5. UNIX for Dummies Questions & Answers

Data file manipulation

Hi, I have two, double column data files (file1 and file2). I want to add the second column of file2 to as 3rd column of file1. But, the 3rd column values corresponds to the values of the 2nd column. example: file1: X Y ========= x1 y2 x3 y4 x2 y4 x5 y3 ========= file2: Y ... (7 Replies)
Discussion started by: gaurab
7 Replies

6. Shell Programming and Scripting

Data manipulation from a file

i have a file in follwing format 0110 1020 1011 1032 1020 2005 2003 1050 i want the output in such a way that all non zero numbers will be converted into 1 like this 0110 1010 1011 1011 1010 1001 1001 1010 (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

7. Shell Programming and Scripting

Data manipulation from one file

HI all i have a file consisting of following numbers 0000 0000 0000 0000 0000 1010 0000 0100 0000 0000 0000 1111 0000 1010 0000 0100 (3 Replies)
Discussion started by: vaibhavkorde
3 Replies

8. UNIX for Dummies Questions & Answers

UNIX - File/Table/Data manipulation

Hi, I have a table (e.g.): a 1 e 4 5 6 b 2 r 4 4 2 c 5 r 3 7 1 d 9 t 4 4 9 . . What I need to do is to set the values of some values in column 2 to negative values. For example, the values 2 and 9 should become -2 and -9 in the modified file. How should I go about... (2 Replies)
Discussion started by: pc2001
2 Replies

9. UNIX for Dummies Questions & Answers

Validating XSL sheet data in Unix Data file

Dear All, Need your help. In my day to day activities I have to validate/search Excel Sheet data (eg.say Application No. 0066782345) data into the Unix environment file whether the same data is present in that file or not. There are hundreds of records coming in excel file and I am doing grep... (1 Reply)
Discussion started by: ravijunghare
1 Replies

10. Shell Programming and Scripting

Unix Shell Novice - File Manipulation

Hi, I am brand new to unix and am hoping someone can start me in the right direction. I want to be able to put the results of a file command such as wc -l filename into a variable which I can then use to test against another variable...i.e. I need to show the nth line of a file, but need to... (3 Replies)
Discussion started by: nmullane
3 Replies
Login or Register to Ask a Question