09-20-2007
extracting a line based on line number
i want to cut all the entries from the /etc/passwd file in which the uid is> 500
for this i was writing this ,m quiet new to all this.. scripting
but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,, which is not allowed ..
my problem is that ,, i have a variable i , which is being incremented n it is containing an integer value as u can c , now i want to print that line which is satisfying the if condition .
because i was not working so i wrote 56 instead of that , as in my passwd file it was havin pid >500 just to test ..
#!/bin/bash
nol=`wc -l /etc/passwd | cut -d " " -f 1`
i=1
if [ $nol -ge $i ]
then
if [ `sed -n '56p' /etc/passwd | cut -d \: -f 3` -ge 500 ]
then
sed -n '56p' /etc/passwd >hii
i=`expr $i + 1`
fi
fi
exit
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
grep "KeyNotFoundException" weblogic.log
After running this command the output is
abcxyzexceptions.KeyNotFoundException: Person not found
How to know ..what is the line number of the above string in the log file. (2 Replies)
Discussion started by: bishweshwar
2 Replies
2. Shell Programming and Scripting
Hi Unix gurus
Basically i am searching for the pattern and getting the line numbers of the grepped pattern. I am trying to print the series of lines from 7 lines before the grepped line number to the grepped line number.
I am trying to use the following code. but it is not working.
cat... (3 Replies)
Discussion started by: mohanm
3 Replies
3. UNIX for Dummies Questions & Answers
Hello Everyone.
I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below:
if ; then
if ; then
tail +$1 $3 | head -n $2
else
... (5 Replies)
Discussion started by: grc
5 Replies
4. Shell Programming and Scripting
I have a file with ~200K lines, I need to delete 4K lines in it. There is no range.
I do have the line numbers of the lines which I want to be deleted.
I did tried using
> cat del.lines
sed '510d;12d;219d;......;3999d' file
> source del.lines
Word too long.
I even tried... (2 Replies)
Discussion started by: novice_man
2 Replies
5. Shell Programming and Scripting
here is the content of input file
CREATE TABLE `bla bla bla` (
`allianceSiteId` int(11) DEFAULT NULL,
`trunkGroupsId` int(11) DEFAULT NULL,
`lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `allianceSiteId`... (4 Replies)
Discussion started by: vivek d r
4 Replies
6. Shell Programming and Scripting
Hi
I have a case where I am grabbing patterns and subsequent lines using
sed -n -e '/regex/{$!N;p;}'
This returns just the regex line when it is the last line of my file.
Now I may have even number of lines in some cases (regex never at end) and odd in very rare cases.
If the line... (6 Replies)
Discussion started by: jamie_123
6 Replies
7. Shell Programming and Scripting
my requirement is,
consider a file output
cat output
blah sdjfhjkd jsdfhjksdh
sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf
hellow there
this doesnt look good
et cetc etc
etcetera
i want to replace a line of line number 4 ("this doesnt look good") with some other line
... (3 Replies)
Discussion started by: vivek d r
3 Replies
8. Shell Programming and Scripting
hi Gurus,
I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example:
abcdefghi high abaddffdd
I want to separate the line to multiple lines for every 4 charactors.
the result should be
abcd
efgh
i hi
gh a
badd
ffdd
Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies
9. Shell Programming and Scripting
Hi I have a file with over a million lines (rows) and I want to split everything from 500,000 to a million into another file (to make the file smaller). Is there a simple command for this?
Thank you
Phil (4 Replies)
Discussion started by: phil_heath
4 Replies
10. Shell Programming and Scripting
Dear All,
I have to solve the following problems with multiple tab-separated text file but I don't know how. Any help would be greatly appreciated. I have access to Linux mint (but not as a professional).
I have multiple tab-delimited files with the following structure:
file1:
1 44
2 ... (5 Replies)
Discussion started by: Bastami
5 Replies
getpw(3C) getpw(3C)
NAME
getpw() - get name from UID
SYNOPSIS
DESCRIPTION
searches the password file for a user ID number that equals uid, copies the line of the password file in which uid was found into the array
pointed to by buf, and returns 0. returns non-zero if uid cannot be found. The line is null-terminated.
This routine is included only for compatibility with prior systems, and should not be used; see getpwent(3C) for routines to use instead.
NETWORKING FEATURES
NFS
This routine is implemented using (see getpwent(3C)) and therefore uses the Network Information Service network database as described in
passwd(4).
RETURN VALUE
returns non-zero on error.
WARNINGS
The above routine uses which causes it to increase, more than might be expected, the size of programs not otherwise using standard I/O.
Obsolescent Interfaces
is to be obsoleted at a future date.
AUTHOR
was developed by AT&T and HP.
FILES
/etc/passwd
SEE ALSO
getpwent(3C), passwd(4), thread_safety(5).
STANDARDS CONFORMANCE
TO BE OBSOLETED getpw(3C)