Help using sed command - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help using sed command

Hello everyone I need help. I am getting the followin error for my cshell script:

neptune% proj2.csh
sed: Unrecognized command: Customers.csv
sed: Unrecognized command: Customers.csv
sed: Unrecognized command: Customers.csv
neptune%


for the program:

#!/usr/bin/csh
####################
#Name: proj2.csh
#Author: Ramon Quiusky
#Description: C-shell script using the Customers.csv and Orders.csv files
#linking the CustomerId from these two files then query these companies: VINET,
HANAR and WANDK from the Customers.csv.
#Display the following information on your web report
#Date:04-28-2004
#####################

#set array=`cat Customers.csv`
#set cust_ar = 0
#set i=0

set Cust_arr=(VINET, HANAR, WANDK)

foreach elmnt ($Cust_arr)

sed Customers.csv | awk -F, '{if($1 ~/'"$elmnt"'/){print $1 " " $3 " " $4}}'

end


and yes, Customers.csv exists and permissions are rw-------

Thanks!

Comments

  • XfactorXfactor Posts: 343Member
    : Hello everyone I need help. I am getting the followin error for my cshell script:
    :
    : neptune% proj2.csh
    : sed: Unrecognized command: Customers.csv
    : sed: Unrecognized command: Customers.csv
    : sed: Unrecognized command: Customers.csv
    : neptune%
    :
    :
    : for the program:
    :
    : #!/usr/bin/csh
    : ####################
    : #Name: proj2.csh
    : #Author: Ramon Quiusky
    : #Description: C-shell script using the Customers.csv and Orders.csv files
    : #linking the CustomerId from these two files then query these companies: VINET,
    : HANAR and WANDK from the Customers.csv.
    : #Display the following information on your web report
    : #Date:04-28-2004
    : #####################
    :
    : #set array=`cat Customers.csv`
    : #set cust_ar = 0
    : #set i=0
    :
    : set Cust_arr=(VINET, HANAR, WANDK)
    :
    : foreach elmnt ($Cust_arr)
    :
    : sed Customers.csv | awk -F, '{if($1 ~/'"$elmnt"'/){print $1 " " $3 " " $4}}'
    :
    : end
    :
    :
    : and yes, Customers.csv exists and permissions are rw-------
    :
    : Thanks!
    :

    You might want to look up the man page for sed because it doesn't look like you're using it right. I'm using bash so I don't know if it's different for csh. Anyway I just tried the command:

    sed filename.txt

    and I got an error. It treated the 'f' as an option. So it basically looks like you're using sed wrong.

    X
  • satharielsathariel Posts: 59Member
    : Hello everyone I need help. I am getting the followin error for my cshell script:
    :
    : neptune% proj2.csh
    : sed: Unrecognized command: Customers.csv
    : sed: Unrecognized command: Customers.csv
    : sed: Unrecognized command: Customers.csv
    : neptune%
    :
    :
    : for the program:
    :
    : #!/usr/bin/csh
    : ####################
    : #Name: proj2.csh
    : #Author: Ramon Quiusky
    : #Description: C-shell script using the Customers.csv and Orders.csv files
    : #linking the CustomerId from these two files then query these companies: VINET,
    : HANAR and WANDK from the Customers.csv.
    : #Display the following information on your web report
    : #Date:04-28-2004
    : #####################
    :
    : #set array=`cat Customers.csv`
    : #set cust_ar = 0
    : #set i=0
    :
    : set Cust_arr=(VINET, HANAR, WANDK)
    :
    : foreach elmnt ($Cust_arr)
    :
    : sed Customers.csv | awk -F, '{if($1 ~/'"$elmnt"'/){print $1 " " $3 " " $4}}'
    :
    : end
    :
    :
    : and yes, Customers.csv exists and permissions are rw-------
    :
    : Thanks!
    :
    :

    Hi,

    You should tell sed what it should do with Customers.csv. Either via a script or in quotes. The way You use it, You can use "cat" instead. Or just leave all from the beginning until the awk command away and put Customers.csv to the end.

    Like:

    [code]
    awk -F, '{if($1 ~/'"$elmnt"'/){print $1 " " $3 " " $4}}' Customers.csv
    [/code]
    [black]SaThaRiel[/black]

    [size=1][blue]Any time things appear to be going better, you have overlooked something.[/blue][/size]

Sign In or Register to comment.