Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
06-29-2012, 11:26 AM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Rep: 
|
started Unix yesterday, im 15 so i don't really know what i'm doing
The output of a file is:
File: IMAGE1.txt
Resolution: 720 x 547
File: IMAGE2.txt
Resolution: 720 x 547
File: IMAGE3.txt
Resolution: 720 x 547
I want it to look like this:
IMAGE1.txt: 720 x 547
IMAGE2.txt: 720 x 547
IMAGE3.txt: 720 x 547
Could somebody please explain how to do this, and also tell me exactly what you are doing. Thank You.
Namaste and good luck!
|
|
|
06-29-2012, 11:42 AM
|
#2
|
Member
Registered: May 2012
Location: London
Distribution: Debian and slackware for uni
Posts: 61
Rep: 
|
? Very vague question, I don't understand.
|
|
|
06-29-2012, 11:48 AM
|
#3
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
me neither.
|
|
|
06-29-2012, 11:57 AM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
first homework assignment?
Regardless, please tell us what commands you have studied. We can help and give hints, but it is established policy not to do the assignment for you.
Here is a big hint: It can be done with a one-line SED command. The general form is this anything in <angle brackets>, means that you should insert the actual code.
Code:
sed -n '/<keyword>/ {<get the next line>; <remove the line feed + the word "resolution">; <print the resulting line>}' <filename> > <newfilename>
|
|
|
06-29-2012, 12:00 PM
|
#5
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
what i was thinking was i would set each file name to y and each resolution to z and then i would use echo to format them with the colon. I really just need to figure out how to set for y and zbecause what I have done already to get where i was at is this:
foreach x (`ls -1 | grep image `)
sed -n 1,2p $x
|
|
|
06-29-2012, 12:00 PM
|
#6
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by brock_pace
me neither.
|
YOU don't know what the question is??!!!----Maybe you should tell us more about what you are doing.
Continuing my previous post: Look up the SED command here: http://www.grymoire.com/Unix/Sed.html
|
|
|
06-29-2012, 12:04 PM
|
#7
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
no, I just dont understand the question. This is a really bad post because this is only my second day using any form of programming.
|
|
|
06-29-2012, 12:05 PM
|
#8
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by brock_pace
what i was thinking was i would set each file name to y and each resolution to z and then i would use echo to format them with the colon. I really just need to figure out how to set for y and zbecause what I have done already to get where i was at is this:
foreach x (`ls -1 | grep image `)
sed -n 1,2p $x
|
You said earlier that the data was in a file--if so, you can't list the data using ls
Is "foreach" a legal command?---I've never seen it before
|
|
|
06-29-2012, 12:08 PM
|
#9
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
yeah foreach is a legal command it just loops your commands, i think
|
|
|
06-29-2012, 12:08 PM
|
#10
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by brock_pace
no, I just dont understand the question. This is a really bad post because this is only my second day using any form of programming.
|
I thought the question was clear: You have a file with the stated contents, and you want a new file with the revised contents. I think you meant to say that you don't know how to do it.
What commands did they teach you before making this assignment?----OR: Did they send you to some documentation to look up the commands?
|
|
|
06-29-2012, 12:09 PM
|
#11
|
Member
Registered: May 2012
Location: London
Distribution: Debian and slackware for uni
Posts: 61
Rep: 
|
If you don't understand the question then how do you expect us to understand? Anyway, that script is wrong. Ls does not list contents of a file. What else have you tried, maybe if you tell us where you are stuck, instead of wanting the answer straight away. You will learn nothing like that sir.
|
|
|
06-29-2012, 12:11 PM
|
#12
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
they told me nothing, on my first day they just said do this, i knew no commands everything ive done so far has been from stuff ive looked up online.
|
|
|
06-29-2012, 12:13 PM
|
#13
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by brock_pace
yeah foreach is a legal command it just loops your commands, i think
|
According to a quick Google search, the term "foreach" is sometimes used to describe a type of loop. The actual command is "for". Using "man foreach" or "man -k foreach" finds nothing.**
"man" is one the very first Linux /Unix commands to learn. enter "man man" to get some details on how it works
|
|
1 members found this post helpful.
|
06-29-2012, 12:13 PM
|
#14
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
im stuck because i dont know how to set the file name as a variable
|
|
|
06-29-2012, 12:16 PM
|
#15
|
LQ Newbie
Registered: Jun 2012
Posts: 23
Original Poster
Rep: 
|
thanks, i didnt know about the foreach thing.
|
|
|
All times are GMT -5. The time now is 04:40 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|