how to read in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to read in shell
# 1  
Old 06-30-2007
how to read in shell

how to read 3rd entry of 6th line from the bottom in /etc/passwd file using shell script
# 2  
Old 06-30-2007
Quote:
Originally Posted by useless79
how to read 3rd entry of 6th line from the bottom in /etc/passwd file using shell script
Code:
awk -F":" ' NR == 6 { print $3 } ' /etc/passwd

# 3  
Old 06-30-2007
Quote:
Originally Posted by useless79
how to read 3rd entry of 6th line from the bottom in /etc/passwd file using shell script
If I understand correctly and by "entry" you mean column:

Code:
awk '{x[NR]=$3}END{print x[NR-5]}' FS=":" /etc/passwd

# 4  
Old 06-30-2007
MySQL "awk"

tail -6 /etc/passwd | head -1 | awk -F":" '{print $3}'
# 5  
Old 06-30-2007
Quote:
Originally Posted by anchal_khare
tail -6 /etc/passwd | head -1 | awk -F":" '{print $3}'
Or (zsh/bash/ksh93):

Code:
< <(tail -6 /etc/passwd) IFS=: read a b c d;echo "$c"

# 6  
Old 06-30-2007
Another way of doing

Code:
tail -6 /etc/passwd | head -1 | cut -d: -f 3

Cheers,
Ozgur
# 7  
Old 07-01-2007
Code:
awk '{ line[NR]=$0} 
     END { 
	         for (i=NR-5; i<=NR; i++) { 
			    n=split(line[i],arr,":")
				print arr[3]
			 } 
		  }'  "/etc/passwd"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to tell php to read shell?

.... Solved.... .. .. Hello, I've read couples of similar threads to my question and I strongly believe that I am doing something wrong. What I'm trying to do is to process data with php. It reads data from shell script. Everything goes well but at the end it does not print what it reads... (0 Replies)
Discussion started by: baris35
0 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

While read line in shell

Guys, I have a requirement like below my cfg file(sam.cfg) has path=/u/sample/test/ path=/u/sample1/test1/ path=/u/sample2/test2/ days=10 file=*.log My script is below, #!/bin/sh ./u/sample/sam.cfg while read line do find $path -name "$file" -mtime +$days -exec ls -la... (2 Replies)
Discussion started by: AraR87
2 Replies

4. Shell Programming and Scripting

read a line using c shell

Hi all, I am using csh to read a line from the terminal. I was told to use $< like the following in the terminal: set name = $< then I write a line: James Bond then I look at the value of 'name': echo $name it is always 'James'. Although the textbook tells me that $< read a... (2 Replies)
Discussion started by: lionheartyoung
2 Replies

5. Programming

How to read output of a shell command

Hello All, I have a an application written in C and runing on Red Hat Linux. In my code I have written a command that is fired on the linux shell by using system() function call. Now I need to read the output of this command in my c program and assign it to a variable. Can anyone... (1 Reply)
Discussion started by: shamik
1 Replies

6. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

7. Programming

read arguments from shell

I have to write a C program using sys call (read, no fread) to read from shell all the parameters, without know how many are them. I tryed in some ways, but I have no success. Any Idea? Can I use read to read from stdin? (1 Reply)
Discussion started by: DNAx86
1 Replies

8. Shell Programming and Scripting

how to read a file using shell ??

Hello i have a file in directory which has some values like this lets assume the file is $p ttry_rtyy_trree and i am using a file as an input as ($Y) in a shell once i start the shell it should read the file $p and $Y once those lines are matched in $Y i want to take a copy of that ... (7 Replies)
Discussion started by: ranga27
7 Replies

9. UNIX for Advanced & Expert Users

How to read from a file in C shell?

Hi All, I want to read some number from a file into a variable in C shell as follows. I know that the syntax in ksh is read x < file name I dont know what's the equivalent for this in C Shell Can some one pls. help me out? Thanks in advance raju (2 Replies)
Discussion started by: rajugp1
2 Replies

10. Shell Programming and Scripting

When does a shell read into memory?

I don't know how to ask this clearly, so I'll try my best... At what point does a shell script stop reading from a file, and begin using the buffered script? Hopefully, this example will shed some light: #!/usr/bin/ksh value="" until ; do sleep 10 print "What is your value?" #print... (5 Replies)
Discussion started by: LivinFree
5 Replies
Login or Register to Ask a Question