Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I have a value stored in x and I need to compare it to the numbers in every other line of a file. The file contains alternating lines of numbers and letters:
I need to compare x to the numbers in every other line without the first four characters of that line. So I want to compare x to 1111, then to 2222, then 3333. This is to be the condition in an if statement:
if [ $x = (line 1 without first four characters) ]
or
if [ $x = (line 3 without first four characters) ]
I know I would have to use something along the lines of = $(sed something) or maybe cut, but I don't know how to reference the file by line.
Let me know if I need to be more clear. Thanks for any help!
Hi,
I have a value stored in x and I need to compare it to the numbers in every other line of a file. The file contains alternating lines of numbers and letters:
I need to compare x to the numbers in every other line without the first four characters of that line. So I want to compare x to 1111, then to 2222, then 3333. This is to be the condition in an if statement:
if [ $x = (line 1 without first four characters) ]
or
if [ $x = (line 3 without first four characters) ]
I know I would have to use something along the lines of = $(sed something) or maybe cut, but I don't know how to reference the file by line.
As with your other thread, post what you've written/tried so far, and tell us where you're stuck, and we'll be happy to help. However, this sounds very much like a homework question, and as a rule, you're not going to get someone here to do it for you.
If you show you've put some effort into things, and tell us where you're stuck, you're much more likely to get a favorable response.
but I don't know how to reference the file by line.
Take a look at the SED addressing options. Examples:
Code:
#print lines by number (3 thru 8):
sed -n '3,8p' filename
#print lines by content (begin with AAA and end with CCC):
sed -n '/AAA/,/CCC/p' filename
#print lines containing at least one number:
sed -n '/[0-9]/p' filename
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.