LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   started Unix yesterday, im 15 so i don't really know what i'm doing (https://www.linuxquestions.org/questions/linux-newbie-8/started-unix-yesterday-im-15-so-i-dont-really-know-what-im-doing-4175414028/)

brock_pace 06-29-2012 11:26 AM

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!

whysoserious 06-29-2012 11:42 AM

? Very vague question, I don't understand.

brock_pace 06-29-2012 11:48 AM

me neither.

pixellany 06-29-2012 11:57 AM

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>

brock_pace 06-29-2012 12:00 PM

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

pixellany 06-29-2012 12:00 PM

Quote:

Originally Posted by brock_pace (Post 4715102)
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

brock_pace 06-29-2012 12:04 PM

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.

pixellany 06-29-2012 12:05 PM

Quote:

Originally Posted by brock_pace (Post 4715114)
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

brock_pace 06-29-2012 12:08 PM

yeah foreach is a legal command it just loops your commands, i think

pixellany 06-29-2012 12:08 PM

Quote:

Originally Posted by brock_pace (Post 4715117)
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?

whysoserious 06-29-2012 12:09 PM

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.

brock_pace 06-29-2012 12:11 PM

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.

pixellany 06-29-2012 12:13 PM

Quote:

Originally Posted by brock_pace (Post 4715123)
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

brock_pace 06-29-2012 12:13 PM

im stuck because i dont know how to set the file name as a variable

brock_pace 06-29-2012 12:16 PM

thanks, i didnt know about the foreach thing.


All times are GMT -5. The time now is 07:10 AM.