Csh reading lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Csh reading lines
# 1  
Old 10-13-2013
Csh reading lines

Hi,
I have been trying to do a little script in Csh, to classify some information of a text document.
My problem appears when i have to calssificate two parts of the same line into different variables, for example in the document appears something like that:

ID NAME
999999,Michel Luka
888888,Lara Croft

In my scrypt, im trying to take first the ID to save it into a variable and second the NAME to save it in another variable, the only thing that i know is that with the code:

Code:
#!/bin/csh

foreach line ( "`cat login.dat`" )
    echo $line
    echo $line | cut -d "," -f 1
    echo $line | cut -d "," -f 2
end

i get printed the two parts, but dont know how to save each part in different variables to do:

echo $ID and $NAME

Thanks, and sorry for my english, today im a bit thick :/
# 2  
Old 10-13-2013
Code:
#!/bin/csh

foreach line ( "`cat login.dat|grep -v ID`" )
    set ID=`echo $line | cut -d "," -f 1`
    set NAME=`echo $line | cut -d "," -f 2`
    echo "$ID // $NAME"
end

csh-programming-considered-harmful

For non csh
Code:
IFS=","
while read ID NAME
do
    echo $ID
    echo $NAME
done<login.dat

HINT: Either seperate the headings as well with a "," or change to done<login.dat|grep -v ID or foreach line ( "`cat login.dat|grep -v ID`" ) accordingly.

Hope this helps

Last edited by sea; 10-13-2013 at 03:12 PM.. Reason: Yeah, should test first in csh, rather than other way around
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading two lines in a while loop and combining the lines

Dear all, I have a file like this: imput scaffold_0 1 scaffold_0 10000 scaffold_0 20000 scaffold_0 25000 scaffold_1 1 scaffold_1 10000 scaffold_1 20000 scaffold_1 23283 and I want the output like this: scaffold_0 1 scaffold_0 10000 scaffold_0 10000 scaffold_0 20000... (6 Replies)
Discussion started by: valente
6 Replies

2. Shell Programming and Scripting

Printing out duplicate lines in a file with Csh

Hi guys, I was wondering if there was an easy solution, using tcsh, to print out lines that appear twice with a given pattern in a file? So if I am looking for lines with "test" in a given file that contains: blah test blah1 blah //don't print this out as it doesn't have... (3 Replies)
Discussion started by: chu816
3 Replies

3. Shell Programming and Scripting

Regarding reading lines into a new file

Hi all, I jut use a loop to read lines from the user and redirect it to a file. echo "Enter the line" while read -r LINE do echo $LINE >> FILE if ;then break fi done input app... (1 Reply)
Discussion started by: Ananthdoss
1 Replies

4. Shell Programming and Scripting

Reading a variable in csh

I have a simple script that sets a value and reads the value in csh: set -x set a = 10 echo $a The output of the script does not show the value of a + set a = 10 + echo any help would be great. (4 Replies)
Discussion started by: pt14
4 Replies

5. Shell Programming and Scripting

reading lines

I want a script that while it read the lines in the file below,it will check if the second variable is greater or equal 10.if less delete the line tom|2 john|5 simms|23 reed|30 paul|11 After running scripts i should get simms|23 reed|30 paul|11 (5 Replies)
Discussion started by: tomjones
5 Replies

6. Shell Programming and Scripting

CSH: step on the lines in a file

Hi, does somebody know how can I step on the lines in a file? I would like to read a file line by line. And after every line I'd like to do other commands. Lets help me! ;) (4 Replies)
Discussion started by: mig8
4 Replies

7. UNIX for Dummies Questions & Answers

Sed command over multiple lines in csh??

hi i have a long sed command in a csh script that won't fit on 1 line. how do i break it up correctly over multiple lines? this doesn't seem to work in csh: sed -e s/template/$IP.$NN/ \ -e s/NRG/6/ \ -e s/inputf/$IS.$NN/ \ -e s/SHIFT/10.0/ <template.egsinp > $IP.$NN.inp i get: sed:... (1 Reply)
Discussion started by: tuathan
1 Replies

8. Shell Programming and Scripting

reading lines

Hi all, I have a file whose content I need to read and get the 3rd line .. ex: one two three What I need is to read a content of third line of this file and print first three characters ... I could print first three characters with "head -c 3" if I could get the content of the third line... (4 Replies)
Discussion started by: c0mrade
4 Replies

9. Shell Programming and Scripting

Reading lines within vi editor

Hi All, I need to read line by line from a file(created using vi editor) till end of the file and pass it to my own executables so that it will read first line and execute and then other and so on...Thanks The steps are like this; 1) read first line in file 2) execute the job with first line as... (2 Replies)
Discussion started by: asriva26
2 Replies

10. UNIX for Advanced & Expert Users

Reading lines within a Unix file.

I have a file that has a list of numbers in it. Each line has a different number. I am trying to create some sort of loop within a script that will pick the numbers up on lines 1 and 2 and then put those figures into the script. It then goes through the process then loops back and reads lines 2 and... (5 Replies)
Discussion started by: mariner
5 Replies
Login or Register to Ask a Question