LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-29-2012, 11:26 AM   #1
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Rep: Reputation: Disabled
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!
 
Old 06-29-2012, 11:42 AM   #2
whysoserious
Member
 
Registered: May 2012
Location: London
Distribution: Debian and slackware for uni
Posts: 61

Rep: Reputation: Disabled
? Very vague question, I don't understand.
 
Old 06-29-2012, 11:48 AM   #3
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
me neither.
 
Old 06-29-2012, 11:57 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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>
 
Old 06-29-2012, 12:00 PM   #5
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
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
 
Old 06-29-2012, 12:00 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by brock_pace View Post
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
 
Old 06-29-2012, 12:04 PM   #7
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-29-2012, 12:05 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by brock_pace View Post
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
 
Old 06-29-2012, 12:08 PM   #9
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
yeah foreach is a legal command it just loops your commands, i think
 
Old 06-29-2012, 12:08 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by brock_pace View Post
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?
 
Old 06-29-2012, 12:09 PM   #11
whysoserious
Member
 
Registered: May 2012
Location: London
Distribution: Debian and slackware for uni
Posts: 61

Rep: Reputation: Disabled
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.
 
Old 06-29-2012, 12:11 PM   #12
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-29-2012, 12:13 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by brock_pace View Post
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.
Old 06-29-2012, 12:13 PM   #14
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
im stuck because i dont know how to set the file name as a variable
 
Old 06-29-2012, 12:16 PM   #15
brock_pace
LQ Newbie
 
Registered: Jun 2012
Posts: 23

Original Poster
Rep: Reputation: Disabled
thanks, i didnt know about the foreach thing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Yesterday's date in unix priyophan Linux - Server 10 03-31-2011 05:33 PM
yesterday had sound ,now don't! ggeo Linux - Hardware 15 11-22-2006 05:24 PM
Unix/Linux Programmer: How do I get started? peaceofcrap2001 Programming 7 06-14-2005 02:24 AM
Yesterday I had audio, today I don't. mimsmall Linspire/Freespire 1 08-09-2004 04:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration