<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unix Tutorial &#187; Questions &amp; Answers</title>
	<atom:link href="http://www.unixtutorial.org/category/questions-answers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unixtutorial.org</link>
	<description>Learn UNIX</description>
	<lastBuildDate>Wed, 03 Mar 2010 22:55:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to identify what Unix groups are available on your system</title>
		<link>http://www.unixtutorial.org/2009/03/how-to-identify-what-unix-groups-are-available-on-your-system/</link>
		<comments>http://www.unixtutorial.org/2009/03/how-to-identify-what-unix-groups-are-available-on-your-system/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 11:11:17 +0000</pubDate>
		<dc:creator>Gleb Reys</dc:creator>
				<category><![CDATA[Questions & Answers]]></category>
		<category><![CDATA[getent]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[unix groups]]></category>

		<guid isPermaLink="false">http://www.unixtutorial.org/?p=513</guid>
		<description><![CDATA[Today, I'd like to answer one of the oldest questions I have in my incoming UnixTutorial questions  email folder. Please leave comments if you need any more help with researching Unix groups on your system.
How to confirm what Unix groups are available
If you remember, a while ago I've introduced you to the getent command. It's [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I'd like to answer one of the oldest questions I have in my incoming <strong>UnixTutorial questions</strong>  email folder. Please leave comments if you need any more help with researching Unix groups on your system.</p>
<h3>How to confirm what Unix groups are available</h3>
<p>If you remember, a while ago I've introduced you to the <a title="getent" href="http://www.unixtutorial.org/commands/getent/"><strong>getent </strong><strong>command</strong></a>. It's a great way of querying various information databases about your systems' users, groups and some other objects. Here's how you would use the command to get a full list of Unix groups known to your system:</p>
<pre>ubuntu# <strong>getent group</strong>
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
...</pre>
<p>This is an abridged output, but I hope you get the idea. This output helps you confirm the following:</p>
<ol>
<li>Unix group name &#8211; first field</li>
<li>Unix group ID (gid) &#8211; third field</li>
<li>All the usernames of members for various groups &#8211; fourh field, unfortunatelly empty for all the groups in my example.</li>
</ol>
<h3>How to confirm the members of a Unix group</h3>
<p>Using the same <strong>getent </strong>command, you can query the groups database using a group name. In my example below, I'm confirming the membership of a <strong>mygroup </strong>Unix group:</p>
<pre>ubuntu# <strong>getent group mygroup</strong>
mygroup:x:1002:user1,greys,user2</pre>
<div>As you can see, <strong>mygroup </strong>has 3 users: user1, greys and user2.</div>
<p>How to determine the number of Unix groups known to your system</p>
<p>One more thing you can learn about your Unix groups using <strong>getent </strong>command is to confirm the overall number of Unix groups &#8211; some scenarious require you to have this number. Here's how you would use getent together with the<strong> wc command</strong> to confirm the number of groups:</p>
<pre>ubuntu# <strong>getent group | wc -l</strong>
62</pre>
<div>That's it for today, let me know if there's anything else you'd like to learn about this topic!</div>
<h3>See also:</h3>
<div>
<ul>
<li><strong><a title="getent command" href="http://www.unixtutorial.org/commands/getent/">Unix getent command</a></strong></li>
<li><strong><a title="list unix groups for a user" href="http://www.unixtutorial.org/2008/07/list-groups-user-belongs-to-in-unix/">List groups a Unix user belongs to</a></strong></li>
<li><strong><a title="unix user id - uid" href="http://www.unixtutorial.org/2008/01/how-to-find-uid-in-unix/">Find out Unix user ID</a></strong></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.unixtutorial.org/2009/03/how-to-identify-what-unix-groups-are-available-on-your-system/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Where, how and why are you using Unix?</title>
		<link>http://www.unixtutorial.org/2009/02/where-how-and-why-are-you-using-unix/</link>
		<comments>http://www.unixtutorial.org/2009/02/where-how-and-why-are-you-using-unix/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 14:16:20 +0000</pubDate>
		<dc:creator>Gleb Reys</dc:creator>
				<category><![CDATA[Questions & Answers]]></category>

		<guid isPermaLink="false">http://www.unixtutorial.org/?p=460</guid>
		<description><![CDATA[Greetings everyone, today's post is going to be a bit different from the usual technical tips and tricks I share. This time around, I need a bit of help myself &#8211; and I hope many of you will be able to answer my questions. Bear with me: it's a lengthy post, but any help is [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings everyone, today's post is going to be a bit different from the usual technical tips and tricks I share. This time around, I need a bit of help myself &#8211; and I hope many of you will be able to answer my questions. Bear with me: it's a lengthy post, but any help is GREATLY APPRECIATED!</p>
<h3>Why am I asking these questions?</h3>
<p>As you remember, a month ago I have offered invited all of the <strong><a href="http://www.unixtutorial.org">Unix Tutorial</a></strong> readers to <a title="Learn Unix with me" href="http://www.unixtutorial.org/2009/01/learn-unix-with-me/">learn Unix together</a>. Everyone benefits from this &#8211; you get a chance to ask the questions which you always wanted answered, and I get to refresh my mind or even conduct a research on new topics just so that I can share the answers and solutions in the easiest to follow form.</p>
<p>I'm currently working on a members area for <strong><a href="http://www.unixtutorial.org">Unix Tutorial</a></strong>, which will eventually have a number of self-paced courses to help you improve your knowledge of Unix and get to the next level of productivity when solving technical problems.</p>
<p><strong>Update</strong>: if you're interested in becoming a member, <a title="unix tutorial membership list" href="http://www.unixtutorial.org/2009/03/join-the-unixtutorial-waiting-list/`">subscribe to the Unix Tutorial waiting list</a>!</p>
<p>But guess what? Without knowing what exactly you do and why you ask the questions about Unix, it's extremely hard to address some of the topics. I would like to give the fullest coverage to everything I present, but at the same time it probably wouldn't make sense to spend much time explaining some concepts most of you are familiar with already.</p>
<p>With this in mind, I'd like you to please take a few moments and help me out by sharing a bit about yourself and your experience with Unix-like operating systems so far. Please feel free to leave comments or use a contact form &#8211; any form of your help will be greatly appreciated.</p>
<h3>Where are you using Unix?</h3>
<p>More likely than not, you have arrived at one of the Unix Tutorial pages while searching for an answer. Webserver logs give me a pretty good idea about your interests and challenges, but they don't reveal one important piece of information: <strong>where do you use your Unix</strong>?</p>
<ul>
<li>Are you a home user with Ubuntu desktop?</li>
<li>Do you have a RedHat Linux desktop at your workplace?</li>
<li>Is the hospital you work for using Unix-based equipment?</li>
<li>Do you have Linux on your PDA or MP3 player?</li>
</ul>
<p>These and many more questions are the ones I'd really like to have answered  &#8211; the nature of my technical tips so far had been rather basic, but some of the comments (and especially the email questions submitted through Unix Tutorial contact form) are so technical that it's obvious their authors have many years of Unix experience.</p>
<h3>How are you using Unix?</h3>
<p>This is another question which really interests me. Recent years saw many Unix-like OS distributions rapidly advance to take up new positions in business solutions of all fields. You can find Unix-like OS in storage and network appliances, desktops, servers, laptops and netbooks, MP3 players and book readers. It's hard to imagine a technological niche which cannot benefit from using a Unix-like system.</p>
<p>So how do you use your Unix?</p>
<ul>
<li>Do you manage Unix servers in your hosting startup?</li>
<li>Do you develop software on a Linux platform?</li>
<li>Are you using Unix in your finance department?</li>
<li>Is Unix-based solution behind your compute grid used for some kind of research?</li>
<li>Are you a professional artist or photographer working in Unix?</li>
<li>Do you compose music or produce podcasts and vidcasts?</li>
</ul>
<p>Let me know about all the ways you've found Unix to be useful so far &#8211; I'm quite often surprised to discover new ways people manage to use the most unusual operating systems, so there's bound to be plenty of interesting ideas about Unix!</p>
<h3>Why are you using Unix?</h3>
<p>This is the last question for today.  Glad to still have you with me, reading this post! I REALLY appreciate your time and willingness to help!</p>
<p>Why are you a Unix user at the moment? Is it because:</p>
<ul>
<li>it's a requirement at work</li>
<li>it's a great family of operating systems which you simply love working with</li>
<li>you're a hacker or a developer</li>
<li>Unix-like OS is the only option you have for the unique task at hand</li>
<li>you've been told Unix is cool</li>
<li>you've been told Unix is so not cool, but got curious and simply couldn't resist</li>
</ul>
<p>Whatever your reason may be, I'd like to know it &#8211; please share your thoughts!</p>
<h3>Thank you!</h3>
<p>Thanks for stopping by and reading through all the questions! I will be delighted to hear back from you about your Unix story, and if there are any questions you decide to ask me &#8211; I'll be happy to answer.</p>
<h3>See also:</h3>
<ul>
<li><strong><a title="join unix tutorial list" href="http://www.unixtutorial.org/2009/03/join-the-unixtutorial-waiting-list/">Join the Unix Tutorial waiting list</a></strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.unixtutorial.org/2009/02/where-how-and-why-are-you-using-unix/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>What to do if numeric id is shown instead of Unix username</title>
		<link>http://www.unixtutorial.org/2009/01/what-to-do-if-numeric-id-is-shown-instead-of-unix-username/</link>
		<comments>http://www.unixtutorial.org/2009/01/what-to-do-if-numeric-id-is-shown-instead-of-unix-username/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 10:50:15 +0000</pubDate>
		<dc:creator>Gleb Reys</dc:creator>
				<category><![CDATA[Advanced topics]]></category>
		<category><![CDATA[Questions & Answers]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.unixtutorial.org/?p=336</guid>
		<description><![CDATA[As you know, every file in your Unix OS belongs to some user and some group. It is very easy to confirm the ownership of any file because user id and group id which own the file are always linked to the file. However, sometimes you can't tell which user owns the file, and today [...]]]></description>
			<content:encoded><![CDATA[<p>As you know, every file in your Unix OS belongs to some user and some group. It is very easy to confirm the ownership of any file because user id and group id which own the file are always linked to the file. However, sometimes you can't tell which user owns the file, and today I'm going to explain why. It's a rather lengthy post and a complicated matter, so please leave questions or comments to help me polish this article off.</p>
<h3>Files and directories ownership in Unix</h3>
<p>If you look at any file using ls command, you will see an output like the one shown below &#8211; it reveals file access permissions, user and group id of the owner, the modification timestamp and the file name itself:</p>
<pre>ubuntu$ <strong>ls -l /tmp/myfile</strong>
-rw-r--r-- 1 greys admin 0 Jan  6 03:51 /tmp/myfile</pre>
<p>In this example, the /tmp/myfile file belongs to me, hence the username is greys. It also belongs to my default (primary) Unix group &#8211; admin.</p>
<p>Similarly, ownership of any file or any directory can be confirmed for every object in available filesystems. Here's just a few more examples, these are the standard system files belonging to root:</p>
<pre>ubuntu$ <strong>ls -ald /etc /etc/passwd</strong>
drwxr-xr-x 91 root root 4096 Jan  6 03:51 /etc
-rw-r--r--  1 root root 1481 Jan  6 03:51 /etc/passwd</pre>
<h3>Why numeric IDs are sometimes shown instead of username or groupname</h3>
<p>Sometimes though, you will look at a file and instead of the username you will see a numeric ID:</p>
<pre>ubuntu# <strong>ls -al /tmp/file</strong>
-rw-r--r-- 1 1006 root 0 Jan  6 03:51 /tmp/file</pre>
<p>The reason numberic ID (<strong>1006 </strong>in the example above) is shown instead of a username is because your system doesn't recognize this ID &#8211; it can't be associated to any username known to your Unix OS.</p>
<p>There are a few possible scenarios for this to happen, but most likely the user has been removed since the file was created. Naturally, deleting any User doesn't automatically mean removing every single file belonging to such a user, that's why the files stay but can no longer be associated with the existing user. All they have to show is the user ID which once owned the file.</p>
<h3>How to find the missing username using user id</h3>
<p>Unfortunately, there are no easy ways to recover the username (or any other user-specific information) based on a misterious user ID some of your files might have. There are a few things can try though.</p>
<ol>
<li><strong> Try other Unix systems in your environment </strong>
<p>It can be the case that Unix account was a local one automatically created by your system administrators. There's still a chance the same uid exists on other systems. Log into a few of them and verify if they have a user with the same user id (read this post for more information: <a title="ways to find user id" href="http://www.unixtutorial.org/2008/01/how-to-find-uid-in-unix/">How to Find Out user id</a>):</p>
<pre>ubuntu$ <strong>getent passwd 1006</strong>
newowner:x:1006:1006::/home/newowner:/bin/sh</pre>
<p>The same tip applies in case of more mature environments where Unix systems don't have local users, but instead rely on NIS or LDAP for accessing user accounts information.</p>
<p>If your system for whatever reason can't access the centralized storage for users, you will experience the same symptoms &#8211; most of files belonging to users will appear to have numeric IDs instead of usernames. Most likely though, you'll have more important problems in this case &#8211; like not being able to log in as anything else but root (which is an administrative account always created locally on each system).</li>
<li><strong>Look at home directories and their owners
<p></strong>When <a title="creating user accounts in unix" href="http://www.unixtutorial.org/2008/12/how-to-create-user-accounts-in-unix/">a new user is added to Unix system</a>, it usually gets a home directory assigned to it. Creating a home directory is not a default behaviour at times, but it's a good practice and so there's a very high probability that the user you're looking for had a home directory. Removing home directories isn't usually done at the same time when a user is removed, so there's also a good chance that even though the user isn't found anymore, the home directory is still there.</p>
<p>What you should be looking for is a home directory which belongs to the same user id which some of the unidentified files of yours belong to.</p>
<p>Simply do an <a href="http://www.unixtutorial.org/commands/ls/">ls command</a> under /home directory and see if any of the directories there appear to have numeric IDs instead of usernames:</p>
<pre>ubuntu# <strong>ls -ald /home/*</strong>
drwxr-xr-x  2 ftp   nogroup  4096 May 22  2007 /home/ftp
drwxr-xr-x 11 greys greys    4096 Dec 13 19:56 /home/greys
drwxr-xr-x  2 1006  admin    4096 Jan  6 04:23 /home/mike</pre>
<p>As you can see, sometimes you might get lucky &#8211; the directory is there, and since most home directories usually have the same name as the username which owns them, you can deduct that the username of the user id <strong>1006 </strong>was "<strong>mike</strong>". You can now recreate Mike's account and it will be immediately reflected for all the files owned by user id <strong>1006</strong>:</p>
<pre>ubuntu# <strong>ls -ald /home/mike</strong>
drwxr-xr-x 2 1006 admin 4096 Jan  6 04:23 /home/mike
root@simplyunix:~# useradd -u 1006 mike
root@simplyunix:~# ls -ald /home/mike /tmp/file
drwxr-xr-x 2 mike admin 4096 Jan  6 04:23 /home/mike
-rw-r--r-- 1 mike root 0 Jan  6 03:51 /tmp/file</pre>
</li>
<li><strong>Look at other users known to your system</strong>Sometimes users are created in batches, and you can guess who the user was by looking which users were created before and after. All you have to do is to use the same <strong>getent passwd </strong>approach for user ids which are smaller or larger than the one you want to identify.
<p>Another way to user other users' information to your advantage is to verify which groups they belong to and to then query the groups to see if they have any members not currently known to your system. This will only work for NIS/LDAP groups, not local ones. What could happen is that even though a user was removed, the username is still listed in a few NIS groups.</li>
</ol>
<p>That's it for today. Hope this post helps you in your investigations, and stay tuned for more!</p>
<h3>See also:</h3>
<ul>
<li><strong><a title="new users in Unix" href="http://www.unixtutorial.org/2008/12/how-to-create-user-accounts-in-unix/">Adding users in Unix</a></strong></li>
<li><strong><a title="list unix groups a user belongs to" href="http://www.unixtutorial.org/2008/07/list-groups-user-belongs-to-in-unix/">How to list groups a Unix user belongs to</a><br />
</strong></li>
<li><strong><a title="find user id" href="http://www.unixtutorial.org/2008/01/how-to-find-uid-in-unix/">How to find out user ID</a></strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.unixtutorial.org/2009/01/what-to-do-if-numeric-id-is-shown-instead-of-unix-username/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Confirm the Day of the Week Based on a Timestamp</title>
		<link>http://www.unixtutorial.org/2008/11/find-day-of-the-week-based-on-a-timestamp/</link>
		<comments>http://www.unixtutorial.org/2008/11/find-day-of-the-week-based-on-a-timestamp/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 15:51:48 +0000</pubDate>
		<dc:creator>Gleb Reys</dc:creator>
				<category><![CDATA[Questions & Answers]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://www.unixtutorial.org/?p=155</guid>
		<description><![CDATA[I recently created a Unix Questions and Answers page, if you have a Unix question &#8211; feel free to ask it there using the submit form and I'll do my best to help you out.
Today's Unix question is this:
How can we write a shell script in unix to find the day of the week when [...]]]></description>
			<content:encoded><![CDATA[<p>I recently created a Unix Questions and Answers page, if you have a Unix question &#8211; feel free to ask it there using the submit form and I'll do my best to help you out.</p>
<p>Today's Unix question is this:</p>
<h4>How can we write a shell script in unix to find the day of the week when date is given?</h4>
<p>The solution for this is even simpler: there's no need for Unix scripting, all you need is to have <a href="http://en.wikipedia.org/wiki/Date_(Unix)">GNU date</a> command at your disposal. I've already shown you all the <a title="date and time calculations in unix" href="http://www.unixtutorial.org/2008/09/easy-date-calculations-in-unix-scripts-with-gnu-date/">basic date/time calculations</a> using this great tool, and that's just another way of using it.</p>
<h3>How to find a Day of the week based on timestamp</h3>
<p>All you need is to know the base date. Let's say I'm interested in October 16th, 2009. Here's how easy it is to confirm that day will be Friday:</p>
<pre>ubuntu$ <strong>date -d "Oct 16 2009" "+%a"</strong>
Fri</pre>
<p>That's it &#8211; enjoy!</p>
<h3>See also:</h3>
<ul>
<li><strong><a title="time and date" href="http://www.unixtutorial.org/2008/06/unix-scripting-time-and-date/">time and date in Unix</a></strong></li>
<li><strong><a title="date manipulations in Unix" href="http://www.unixtutorial.org/2008/09/easy-date-calculations-in-unix-scripts-with-gnu-date/">date calculations with GNU date command</a><br />
</strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.unixtutorial.org/2008/11/find-day-of-the-week-based-on-a-timestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Parse Text Files Line by Line in Unix scripts</title>
		<link>http://www.unixtutorial.org/2008/08/how-to-parse-text-files-line-by-line-in-unix-scripts/</link>
		<comments>http://www.unixtutorial.org/2008/08/how-to-parse-text-files-line-by-line-in-unix-scripts/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 16:40:38 +0000</pubDate>
		<dc:creator>Gleb Reys</dc:creator>
				<category><![CDATA[Questions & Answers]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.unixtutorial.org/?p=62</guid>
		<description><![CDATA[I'm finally back from my holidays and thrilled to be sharing next of my Unix tips with you!
Today I'd like to talk about parsing text files in Unix shell scripts. This is one of the really popular areas of scripting, and there's a few quite typical limitations which everyone comes across.
Reading text files in Unix [...]]]></description>
			<content:encoded><![CDATA[<p>I'm finally back from my holidays and thrilled to be sharing next of my Unix tips with you!</p>
<p>Today I'd like to talk about parsing text files in Unix shell scripts. This is one of the really popular areas of scripting, and there's a few quite typical limitations which everyone comes across.</p>
<h3>Reading text files in Unix shell</h3>
<p>If we agree that by "reading a text file" we assume a procedure of going through all the lines found in a clear text file with a view to somehow process the data, then <a title="unix cat" href="http://www.unixtutorial.org/commands/cat/"><strong>cat command</strong></a> would be the simplest demonstration of such procedure:</p>
<pre>redhat$ <strong>cat /etc/redhat-release</strong>
Red Hat Enterprise Linux Client release 5 (Tikanga)</pre>
<p>As you can see, there's only one line in the <strong>/etc/redhat-release</strong> file, and we see what this line is.</p>
<p>But if you for whatever reason wanted to read this file from a script and assign the whole release information line to a Unix variable, using cat output would not work as expected:</p>
<pre>bash-3.1$ <strong>for i in `cat /etc/redhat-release`; do echo $i; done;</strong>
RedHat
Enterprise
Linux
Client
release
5
(Tikanga)</pre>
<p>Instead of reading a line of text from the file, our one-liner splits the line and outputs every word on a separate line of the output. This happens because of the shell syntax parsing &#8211; Unix shells assume space to be a delimiter of various elements in a list, so when you do a for loop, Unix shell interpreter treats each line with spaces as a list of elements, splits it and returns elements one by one.</p>
<h3>How to read text files line by line</h3>
<p>Here's what I decided: if I can't make Unix shell ignore the spaces between words of each line of text, I'll disguise these spaces. Since my solution was getting pretty bulky for a one-liner, I've made it into a script. Here it is:</p>
<pre>bash-3.1$ <strong>cat /tmp/cat.sh</strong>
#!/bin/sh
FILE=$1
UNIQUE='-={GR}=-'
#
if [ -z "$FILE" ]; then
        exit;
fi;
#
for LINE in `sed "s/ /$UNIQUE/g" $FILE`; do
        LINE=`echo $LINE | sed "s/$UNIQUE/ /g"`;
        echo $LINE;
done;</pre>
<p>As you can see, I've introduced an idea of a UNIQUE variable, something containing a unique combination of characters which I can use to replace spaces in the original string. This variable needs to be a unique combination in a context of your text files, because later we turn the string back into its original version, replacing all the instances of $UNIQUE text with plain spaces.</p>
<p>Since most of the needs of mine required such functionality for a relatively small text files, this rather expensive (in terms of CPU cycles) approach proved to be quite usable and pretty fast.</p>
<p><strong>Update: </strong>please see comments to this post for a much better approach to the same problem. Thanks again, Nails!</p>
<p>Here's how my script would work on the already known <strong>/etc/redhat-release</strong> file:</p>
<pre>bash-3.1$ <strong>/tmp/cat.sh /etc/redhat-release</strong>
Red Hat Enterprise Linux Client release 5 (Tikanga)</pre>
<p>Exactly what I wanted! Hopefully this little trick will save some of your time as well. Let me know if you like it or know an even better one yourself!</p>
<h3>Related books</h3>
<p>If you want to learn more, here's a great book:</p>
<div id="attachment_363" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.amazon.com/gp/product/0596005954?ie=UTF8&#038;tag=unixtutorial-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0596005954"><br />
<img class="size-full wp-image-379" title="classic-shell-scripting" src="http://www.unixtutorial.org/images/classic-shell-scripting.jpg" alt="classic-shell-scripting" width="150" height="150" /></a><p class="wp-caption-text">Classic Shell Scripting</p></div>
<h3>See also:</h3>
<ul>
<li><strong><a title="Unix variables" href="http://www.unixtutorial.org/2008/05/variables-in-unix-shell/">Using variables in scripts</a></strong></li>
<li><strong><a title="Time and date in Unix" href="http://www.unixtutorial.org/2008/06/unix-scripting-time-and-date/">Unix scripting: time and date</a></strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.unixtutorial.org/2008/08/how-to-parse-text-files-line-by-line-in-unix-scripts/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
