Help with cut and tail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with cut and tail
# 1  
Old 12-21-2009
Help with cut and tail

Hey!!

I'm having a hard time getting this to work!

I need to input a name and compare that name to a file in the file the name has a code on the same line as it, what i need is to compare the input name with the file and then output the code to a other file.

Ex:
code;name;xxxx;xxxx


can any one help me ??? i'm programing shell script bash
# 2  
Old 12-21-2009
Code:
filename="something.txt"
awk -F ';'  -v fname=$filename ' $2==fname {print $1}' oldfile > newfile

# 3  
Old 12-21-2009
Thanks but I can't get that to work
# 4  
Old 12-21-2009
Quote:
Originally Posted by nogame11
Thanks but I can't get that to work
If not works, please show your input files, and desired output.
# 5  
Old 12-21-2009
this is what I need
I type in a name that is already in a file like

code;name;location;date
code;name;location;date

now I need to find the name I inputed in the file so I can get its code
and output it's code to a other file
# 6  
Old 12-21-2009
Maybe this then ?

Code:
$
$ cat -n f5
     1  code1;name1;location1;date1
     2  code2;name2;location2;date2
$
$ awk -F';' -v name="name1" '$2==name {print $1}' f5
code1
$
$ awk -F';' -v name="name2" '$2==name {print $1}' f5
code2
$
$

tyler_durden
# 7  
Old 12-23-2009
can anybody tell me why is code does not work ??

it never enter's the if even when the name is right
Code:
echo "Name:"
read Name

prev=`cut -d ";" -f1-3 funcionarios.cvs`

for linha in "$prev"
do
     fun=`echo "$linha" | cut -d ";" -f2`
     if [ "$Nome" = "fun" ]; then
          echo "It's the same"
     fi
done

thanks

Last edited by Scott; 12-23-2009 at 11:38 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using :<<cut / cut to comment out block of bash script

I am using : << cut / cut to comment out block of code. Works fine on few lines of script, then it gives me this cryptic error when I try to comment out about 80 lines. The "warning " is at last line of script. done < results 169 echo "END read all positioning parameters" 170... (8 Replies)
Discussion started by: annacreek
8 Replies

2. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

3. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

4. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

5. Shell Programming and Scripting

tail, grep and cut

Hello all, I have some weird problem that kinda baffles me. Say I have the following test file: claudia:~/tmp$ cat testfile.txt This is a test line This is the second test line And yeah, this is the third test line Then say I want to tail the file, grep for the word "third" then... (7 Replies)
Discussion started by: sylaan
7 Replies
Login or Register to Ask a Question