Unix/Linux Go Back    

Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

file as input for script

Shell Programming and Scripting

Closed Linux or Unix Question    
Thread Tools Search this Thread Display Modes
Old Unix and Linux 11-11-2004
finster's Unix or Linux Image
finster finster is offline
Registered User
Join Date: Nov 2002
Last Activity: 14 September 2013, 10:43 PM EDT
Location: USA
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
file as input for script

how do I use a file (comma seperated) as an input for a script in bin/sh?


I have a script that :


echo "$Input1, $Input2, $Input3,$Input4" (or some other function)

If I have a .csv file which lists many rows of input:

etc... (Input1,Input2,Input3,Input4)

How do I use this file for the input of what ever I make the script do? The input will be changed frequently, so I would like to just edit the .csv file, and have the script update the info.

Sponsored Links
Old Unix and Linux 11-11-2004
zazzybob's Unix or Linux Image
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
Join Date: Dec 2003
Last Activity: 13 May 2013, 9:02 AM EDT
Location: Melbourne, Australia
Posts: 2,185
Thanks: 3
Thanked 25 Times in 23 Posts
As long as the number of fields are fixed (and there is no

whitespace in the fields), a quick script like


 while read line
   nocommas=`echo $line | tr ',' ' '`
   set -- $nocommas
   echo "$1 $2 $3 $4"
 done < foo.csv

should do the job

If there is whitespace, then use awk


while read line
  set -- `echo $line | awk -vFS=',' '{print $1,$2,$3,$4}'`
  echo "$1 $2 $3 $4"
done < foo.csv

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Input file to bash script Johanni Shell Programming and Scripting 2 01-25-2012 05:56 PM
AWK Script to convert input file(s) to output file jason_v_brown Shell Programming and Scripting 9 08-29-2010 09:51 PM
Need a script that will read from 2 input file syahmed Shell Programming and Scripting 3 04-13-2010 12:55 PM
Need script to take input from file, match on it in file 2 and input data darkoth Shell Programming and Scripting 1 11-03-2009 10:53 AM
File as input for a script innocentspirit Shell Programming and Scripting 5 10-26-2007 12:03 AM

All times are GMT -4. The time now is 11:28 PM.