Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

file as input for script

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 11-11-2004   -   Original Discussion by finster
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   -   Original Discussion by finster
zazzybob's Unix or Linux Image
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
Join Date: Dec 2003
Last Activity: 2 October 2017, 12:19 PM EDT
Location: /dev/null
Posts: 2,187
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

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 06:56 PM
AWK Script to convert input file(s) to output file jason_v_brown Shell Programming and Scripting 9 08-29-2010 10:51 PM
Need a script that will read from 2 input file syahmed Shell Programming and Scripting 3 04-13-2010 01: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 11:53 AM

All times are GMT -4. The time now is 04:24 AM.