parsing comma separated file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing comma separated file
# 1  
Old 01-05-2011
parsing comma separated file

Hi,

I have a file with th elist of patches separated by comma, like below:
patch1, patch 2, patch 3................

t\The number of patches is not known as it changes every time.

I need assistance in writing a routine such as it will take patch1 as first variable and performs the installation, then reads the file again takes patch2 as value and perform installation.

I have a shell script which perform the installation but i pass one value at a time. i want to run it in a single shot.

Thanks for all th ehelp in advance.
# 2  
Old 01-05-2011
Try:
Code:
( IFS=,
  while read line
  do 
    for i in $line
    do 
      install "$i"
    done
  done
) < infile

# 3  
Old 01-05-2011
thanks!!!!!

here's my sript:

Code:
#!/bin/bash
INPUT=/tmp/patch_list.txt
( IFS=,
  while read PATCHES
  do
    for i in $PATCHES
    do
      echo $PATCHES
    done
  done
) < $INPUT


patch_list.txt has following values:

Code:
SW06859140F110.1039274,SW06859140F110.1039276,SW06859140F110.1039289

when i run the routine it removes the comma and gives all the patches mlike below:

Code:
SW06859140F110.1039274 SW06859140F110.1039276 SW06859140F110.1039289


what i am looking for is one value at a time, some thing like below:

Code:
SW06859140F110.1039274
SW06859140F110.1039276
SW06859140F110.1039289

thanks for all the help in advance.

Last edited by radoulov; 01-05-2011 at 05:04 PM.. Reason: Code tags ...
# 4  
Old 01-05-2011
Code:
awk -F, '{for(i=1;i<=NF;i++) a[++j]=$i;next;}END{for(i=1;i<=j;i++) print a[i];}' $INPUT | while read PATCHES
do
echo $PATCHES
done

# 5  
Old 01-05-2011
@avikaljain

Replace: echo $PATCHES with echo "$i"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing Comma Separated values to UNIX variable from PLSQL

Hi All, I'm trying to pass the comma separated values (string) returned from Plsql Procedure to UNIX variable. getting the below log message cat: -: Bad file descriptor awk: cmd. line:1: fatal: error reading input file `-': Bad file descriptor The output coming from plsql procedure is... (3 Replies)
Discussion started by: Mahesh3089
3 Replies

2. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

3. Shell Programming and Scripting

Needs help in parsing comma separated values

hello experts, i am retrieving values in variables jobKey and jobName within my shell script. these values are returned to me within braces and i am using following command to remove those braces: jobKeys=`echo $jobKeys | sed 's:^.\(.*\).$:\1:'` jobNames=`echo $jobNames | sed... (1 Reply)
Discussion started by: avikaljain
1 Replies

4. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

5. Shell Programming and Scripting

How to split the comma separated file?

Hi, I have a filein unix like ABC,CDE BCD,KHL and the output i need is like column1 column2 ABC,CDE ABC ABC,CDE CDE BCD,KHL BCD BCD,KHL KHL. Can some body help me out? Hi, The code is working fine. But in my file each row does not have always 1 comma. It may... (6 Replies)
Discussion started by: jagdishrout
6 Replies

6. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

7. Shell Programming and Scripting

Comma separated file

Hi all, I have the following files types: FileA: 100, 23, 33, FileB: 22, 45, 78, and i want to make File C: 100,22 23,45 33,78 any nice suggestions for making it easy. (3 Replies)
Discussion started by: hen1610
3 Replies

8. Shell Programming and Scripting

Parsing and filtering multiline text into comma separated line

I have a log file that contains several reports with following format. <Start of delimiter> Report1 header Report1 header continue Report1 header continue Record1 header Record1 header continue Record1 header continue field1 field2 field3 field4 ------... (1 Reply)
Discussion started by: yoda9691
1 Replies

9. Shell Programming and Scripting

How to format file into comma separated field

Guys, Need you help, i have a a file content that look like this. Nokia 3330 <spaces><spaces><more spaces>+76451883874 Nokia 3610 +87467361615 so on and so forth, - there are so many spaces in between. - e.g.... (5 Replies)
Discussion started by: shtobias
5 Replies

10. Shell Programming and Scripting

Parsing Comma separated Arguments

Hi unix guru's I want to execute a shell script like ksh printdetails.ksh Andy,Bob,Daisy,Johnson like passing all the four names in the as the arguments and these arguments are varies between 1 to 10. How to pass these names to the shell script variable. and also i want to know the count... (4 Replies)
Discussion started by: Reddy482
4 Replies
Login or Register to Ask a Question