Top Forums Shell Programming and Scripting extracting a line based on line number Post 302136848 by narendra.pant on Thursday 20th of September 2007 03:22:04 AM
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 ..

nol=`wc -l /etc/passwd | cut -d " " -f 1`
if [ $nol -ge $i ]
if [ `sed -n '56p' /etc/passwd | cut -d \: -f 3` -ge 500 ]
sed -n '56p' /etc/passwd >hii
i=`expr $i + 1`
Test Your Knowledge in Computers #441
Difficulty: Easy
"Hotel California" by the Eagles is a song about a super A.I. who goes rouge and parties all day and night.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

getting the line number by extracting a line

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

Print selection of line based on line number

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

How to read contents of a file from a given line number upto line number again specified by user

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

Delete lines based on line number

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

error while extracting a line from a file based on identifier

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

Line number based manipulation

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

sed command to replace a line at a specific line number with some other line

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

[Solved] How to separate one line to mutiple line based on certain number of characters?

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

Splitting a file based on line number

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

Extracting values based on line-column numbers from multiple text files

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(3)						     Linux Programmer's Manual							  GETPW(3)

getpw - reconstruct password line entry SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include <sys/types.h> #include <pwd.h> int getpw(uid_t uid, char *buf); DESCRIPTION
The getpw() function reconstructs the password line entry for the given user ID uid in the buffer buf. The returned buffer contains a line of format name:passwd:uid:gid:gecos:dir:shell The passwd structure is defined in <pwd.h> as follows: struct passwd { char *pw_name; /* username */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user ID */ gid_t pw_gid; /* group ID */ char *pw_gecos; /* user information */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ }; For more information about the fields of this structure, see passwd(5). RETURN VALUE
The getpw() function returns 0 on success; on error, it returns -1, and errno is set to indicate the error. If uid is not found in the password database, getpw() returns -1, sets errno to 0, and leaves buf unchanged. ERRORS
0 or ENOENT No user corresponding to uid. EINVAL buf is NULL. ENOMEM Insufficient memory to allocate passwd structure. FILES
/etc/passwd password database file ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +----------+---------------+----------------+ |Interface | Attribute | Value | +----------+---------------+----------------+ |getpw() | Thread safety | MT-Safe locale | +----------+---------------+----------------+ CONFORMING TO
The getpw() function is dangerous as it may overflow the provided buffer buf. It is obsoleted by getpwuid(3). SEE ALSO
endpwent(3), fgetpwent(3), getpwent(3), getpwnam(3), getpwuid(3), putpwent(3), setpwent(3), passwd(5) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at GNU
2017-09-15 GETPW(3)

Featured Tech Videos

All times are GMT -4. The time now is 02:24 PM.
Unix & Linux Forums Content Copyright 1993-2019. All Rights Reserved.
Privacy Policy