LinuxQuestions.org
Register a domain and help support LQ
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 01-19-2012, 11:16 AM   #1
GR14
LQ Newbie
 
Registered: Jan 2012
Location: Croatia
Distribution: Windows XP
Posts: 7

Rep: Reputation: Disabled
Manipulating with files, directories / archiving via the Command Line


First to get this out of the way:

I am a complete and utter newbie. I don't use Linux. I have never worked in the command line. Now I have an assignment that needs to be done in Linux' command line.

Now for some backstory:

This is in fact a school assignment, which would be an equivalent to Linux Command Line 101. Except that the course is organized poorly, and we have even worse learning materials. So when I see something like

sed 's/\([a-z][a-z]*\) \([a-z][a-z]*\)/\2 \1/'

I get a severe headache. I have no aspirations to work with the command line in the future, or to use Linux for that matter. This is not to diss on either of them, but I simply have no interest whatsoever in them.

That said, I've tried to solve these by myself. But due to my lack of general knowledge on the topic, and the extremely poor learning materials mentioned earlier, I didn't succeed. All I get are errors, then I spend 15 minutes browsing through various guides and how-to's, only to encounter an error again.

This will be a breeze to you linux users, but to me it's a nightmare and to speak quite frankly, I'm sick of it all. If someone could provide solutions to the following problems, I'd be very much obliged.

It would help me immensely because the course exams will be very similar to this assignment, and I could analyze the command structure and see what it does, and figure out the rest myself well enough to pass the damn exam.

Now that the extensive intro is over, here's the actual assignment questions:

A-1. In your home directory create a directory named test2a and access the directory. / SOLVED

A-2. Write the output from the locale –m command to file file1.txt. / SOLVED

A-3. From file1.txt, using sed, search out for any lines beginning with 'IBM' and ending with an odd number. Write those lines (using the appropriate flag) to file2.txt, without printing them out on the screen.

A-4. Write the following sentences in file3.txt, each in a different row: / THIS IS NOT A PROBLEM

I think that that that that that man used is correct.
Supposing that I don't understand it, and that I don't know it, what shall I do?
I know that you will do well on your exam.

From file3.txt, using sed, replace the sequence ‘this’ with ‘THAT’, but after its second appearance, while simultaneously writing the results in file4.txt and forward them to the tool less. / THIS IS A PROBLEM

A-5. Write out the last 8 lines from file1.txt and count how many characters those lines have.

B-6. In file3.txt, transform every lower case vowel into a capital letter located 2 places after it (example: a -> C, u -> Z). Sort this output in reverse alphabetical order.

A-7. Compress file1.txt and file2.txt using bzip2.

A-8. Make and compress an archive named IspitArh.tar.gz which will contain file3.txt and file4.txt.

A-9. Print out on your screen detailed information (permissions, filesize, revision date, and name) of every file contained within IspitArh.tar.gz, without unpacking the archive.

A-10. In your home directory create a directory named zadatak10, and decompress and unpack the contents of the archive IspitArh.tar.gz into it.

Thank you for the responses.
 
Old 01-19-2012, 11:24 AM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
Are you serious?

Quote:
I have no aspirations to work with the command line in the future, or to use Linux for that matter. This is not to diss on either of them, but I simply have no interest whatsoever in them.
[mod_edit]You're missing out big time![/mod_edit]

Last edited by Tinkster; 01-19-2012 at 06:56 PM. Reason: Keeping LQ a friendly place
 
Old 01-19-2012, 11:28 AM   #3
nonamedotc
Member
 
Registered: Mar 2011
Location: /
Distribution: Fedora (typically latest release or development release)
Posts: 370

Rep: Reputation: Disabled
Since you say you are getting errors, could you post what you tried and what error you are getting? This would be your best chance of getting somewhere, in my opinion.

For some questions, like A-7, A-8, use the man pages on linux. Type man bzip2 or man tar and take a look at the different options available. This might already help you answer these.

As far as I know, people in the forums do not generally answer assignment questions. Good luck.
 
Old 01-19-2012, 11:28 AM   #4
snowpine
Senior Member
 
Registered: Feb 2009
Posts: 4,037

Rep: Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099
Welcome to the forums! At least you were honest about the situation.

If your course materials are poorly written, the good news is there's a ton of helpful material available for free on the web, for example: http://www.tuxfiles.org/linuxhelp/cli.html

You will have to do your own homework, of course, but hopefully we can steer you to the right resources to kindle your love of Linux and learning.
 
Old 01-19-2012, 06:01 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Ignore Post 2....

I concur with posts 3 & 4.
Please show us what you've got so far and we'll help you debug. As you say, you'll be on your own in the exam, so regardless of future plans, you'll need to learn this for now.
We don't just hand out answers as a rule.

You may find these links useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/


The sed guide here http://www.grymoire.com/Unix/ is very good.
 
Old 01-19-2012, 06:57 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by jhwilliams View Post
Are you serious?



[mod_edit]You're missing out big time![/mod_edit]
I"d like to ask you to refrain from that kind of comments in the future
(That's what was there BEFORE my edit).



Cheers,
Tink
 
Old 01-21-2012, 05:38 PM   #7
GR14
LQ Newbie
 
Registered: Jan 2012
Location: Croatia
Distribution: Windows XP
Posts: 7

Original Poster
Rep: Reputation: Disabled
I appreciate all the users pointing me to learning materials, but the thing is - I'm not here for learning; I'm here for a shortcut. As it is, I have 4 other exams next week, in addition to this one. I have not the time nor will to explore 60 pages of manuals on a single command like 'sed', and spend hours as a total newbie to make my way though it by trial and error. I've tried the man pages and to someone inexperienced they're a total waste of time. I'd need man pages for the man pages; maybe then I'd get something out of them.

So, my plan for the exam is simply to memorize these lines from this assignment by heart and the questions to which they belonged, and since the questions in the exam will be very similar to them I hope that I'll be able to recall enough to earn me a passing grade, and never look back at it again.

And true, this is a school assignment, and I certainly wouldn't be so inconsiderate to bother people with solving my assignments if it were something time consuming. But the answers to these 10 questions come in the form of 15 lines at most. To experienced users it's, what, 5-10 minutes of work? That's the reason why I asked for help in the first place. If you are willing to help, I thank you.

Someone asked what I got so far. It's this:

A-1. mkdir test2a; cd test2a

A-2. locale -m > file1.txt

A-3. sed -n -e '/^IBM.*[13579]$/p' file1.txt > file2.txt

A-4. After I create file3.txt with the sentences: sed -e 's/that/THAT/2' file3.txt | tee file4.txt | less

ERROR: It changes only the second 'that' to 'THAT', not all the 'that' after the second occurring as it should.

It also doesn't get me straight back to the command line interface where I can write & stuff, but locks me on a screen with many '~' dispalyed in a column (one in each line) and I have to press I don't know what to get out to the "normal" command line again. I pressed my entire keyboard and obviously hit the correct key to get out where I wanted, but which ones - I don't have a clue.

A-5. tail -8 file1.txt | wc -m

I can't get it to print both the 8 required lines AND the number of chars in them. I can onyl get one of the two. I suppose there is some super cool pipelining forwarding command I am not aware of to do this job. Maybe something like this: tail -8 file1.txt | sfrth - a -f -g -u -z *![trc]../ /p /g/p | (.)*?///(.)(.) --trlz --mkrdbrvr \s\w\r\*D | wc -m ?

A-6. tr aeiou CGKQW < file3.txt | sort -R

ERROR: None really, but... I found the way to do this with 'tr' command. Sstill don't know why I need a '<' before file3.txt to get it work, while in other commands the '<' is not needed. Took me 45 minutes to figure the damn thing out! And guess where I didn't find the solution? In the man pages!

Anyway, since I don't remember 'tr' from our... ahem... "classes", which means we haven't worked with it, is there a way to do this with the almighty 'sed' which we're encouraged to use all the time because it's so.. almighty?

A-7. bzip2 file1.txt file2.txt

A-8. tar cvzf IspitArh.tar.gz file3.txt file4.txt

A-9. tar tvzf IspitArh.tar.gz

I'm actually not sure if A-7, A-8 or A-10 work, i.e. do what they're supposed to do. However, I get no errors, and I see files present that weren't present before so I presume they do work.

A-10. mkdir zadatak10
cd zadatak10
tar xvzf ../IspitArh.tar.gz

ERROR: I get an error on the third line. Something about not being able to find directories or whatnot. In short, it's not working.

So here it is. If someone's willing to give me correct commands for the questions with errors, I'd be much obliged.
 
Old 01-21-2012, 05:47 PM   #8
snowpine
Senior Member
 
Registered: Feb 2009
Posts: 4,037

Rep: Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099Reputation: 1099
Somebody is getting paid to teach you this material, yes? In the two days since you came to us looking for a shortcut, have you spoken with this person whose job is to educate you about your questions and concerns?

Last edited by snowpine; 01-21-2012 at 05:51 PM.
 
Old 01-21-2012, 08:16 PM   #9
GR14
LQ Newbie
 
Registered: Jan 2012
Location: Croatia
Distribution: Windows XP
Posts: 7

Original Poster
Rep: Reputation: Disabled
And I should tell that person what? That the course and its contents are utter BS?

Look, I don't want to be rude to you people, because you haven't been rude to me, but I don't wish to lose anymore time and beat around the bush. So here is it straight-up: I don't like command lines, not Windows' and Linux's even less. Alas, I'm stuck with the latter for the time being. You'll excuse me if I sound bitter, but currently I'm fed up with Linux, CL, and all these shenanigans.

So, one last time: is someone willing to spend 5 minutes and give me straight-up answers by providing me with the lines I need or no? If yes, then you have my gratitude. If no, then I'll say goodbye, take my leave and not waste any more of yours or my time.
 
Old 01-22-2012, 04:17 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by GR14 View Post
A-10. mkdir zadatak10
cd zadatak10
tar xvzf ../IspitArh.tar.gz

ERROR: I get an error on the third line. Something about not being able to find directories or whatnot. In short, it's not working.
The error message is self-explanatory. Have you checked that the file "IspitArh.tar.gz" exists in the directory ".." (which is shorthand for the parent directory of the one you're in)? Are you getting the name right (including the capitalisation, as file and directory names are case-sensitive in Linux)? The commands pwd and ls may be useful. The former will tell you which directory you're in (which won't be useful if the shell prompt displays that info) and the latter will list the files in the directory specified (if none is given, the current directory is used).
 
Old 01-22-2012, 09:38 AM   #11
GR14
LQ Newbie
 
Registered: Jan 2012
Location: Croatia
Distribution: Windows XP
Posts: 7

Original Poster
Rep: Reputation: Disabled
@Nylex

Yes, the error is self-explanatory, but the solution is not. After A-6, I am located in /home/user/test2a, where test2a a contains the following files: file1.txt, file2.txt, file3.txt and file4.txt.

Now, after compressing file1.txt & file2.txt with bzip2 (A-7) I am still in test2a with the following contents file1.txt.bz2, file2.txt.bz2, file3.txt and file4.txt. The first two file are shown in red letters.

After creating and compressing an archive named IspitArh.tar.gz which will contain file3.txt and file4.txt (A-8) I have the following in folder test2a: file1.txt.bz2, file2.txt.bz2, file3.txt, file4.txt and the newly formed IspitArh.tar.gz.

A-9 does not create new files, so skipping to A-10, I have to untar and decompress the contents of IspitArh.tar.gz into the folder zadatak10 which is located in home/user, from the folder where I'm currently at - which is home/user/ispit2a.

My actions:
1. with mkdir ../zadatak10 I create the folder zadatak10 in home/user/
2. from home/user/test2a I type tar -xvzf IspitArh.tar.gz ../zadatak10
3. I get errors which I simply don't understand.

I wasted an hour before I found a post on some forum which mentioned the -C option, or flag, or whatever it is called. After typing: tar -zxvf IspitArh.tar.gz -C ../zadatak10 it worked. If the man pages were a little more comprehensible, offering more info than

Quote:
-C, --directory DIR
change to directory DIR
I would've been able to figure that out earlier. Anyway, it's been solved.

I do have one more question though: what does less do, exactly? In A-4, after forwarding the output to less, I get to a blank screen, where I have to press CTRL + random key to stop the process and get back to the "normal" command line.

Last edited by GR14; 01-22-2012 at 09:40 AM.
 
Old 01-22-2012, 10:10 AM   #12
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by GR14 View Post
I do have one more question though: what does less do, exactly? In A-4, after forwarding the output to less, I get to a blank screen, where I have to press CTRL + random key to stop the process and get back to the "normal" command line.
Less is a pager. It allows you to move backwards and forwards through text (whether that text is in a file, or the output from some commands). You're likely to be using it when you read man pages, for example. You can press 'q' to quit Less. It sounds like perhaps something went wrong with the commands generating the output you're sending to Less, so check those are working as you expect first.
 
1 members found this post helpful.
Old 01-22-2012, 10:27 AM   #13
GR14
LQ Newbie
 
Registered: Jan 2012
Location: Croatia
Distribution: Windows XP
Posts: 7

Original Poster
Rep: Reputation: Disabled
I write the following sentences into file3.txt:

Quote:
I think that that that that that man used is correct.
Supposing that I don't understand it, and that I don't know it, what shall I do?
I know that you will do well on your exam.
Then I need to replace using sed in file3.txt, the sequence ‘that’ with ‘THAT’, but after its second appearance, then writing the results in file4.txt, then forwarding them to the tool less.

The command I ultimately used is: sed -e 's/that/THAT/2g' file3.txt | tee file4.txt | less.

sed -e 's/that/THAT/2g' file3.txt | tee file4.txt does what it's supposed to do. But when I add | less to get sed -e 's/that/THAT/2g' file3.txt | tee file4.txt | less I'm stuck on that blank screen unless I terminate whatever process was initiated by that command. Since I'm clueless in Linux / command line, I know not what it is.

P. S. I'm not sure what the -e option in sed does, but the command works. The man pages are useless to me as usual, because all they say is:

Quote:
-e script, --expression=script
add the script to the commands to be executed
(Add script? What script? What is a 'script' in this instance exactly?)

I only use the -e because I've seen it used in the few examples we did in class.
 
Old 01-22-2012, 10:47 AM   #14
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I'm not sure why you're getting a blank screen when you send the output to less; it's working fine for me. In case you don't know what tee does, it sends output to both standard out (i.e. displayed on the terminal) and to the file specified. As you say, the sed command does work correctly and produces output, which is being sent to the terminal and to file4.txt. So, less should show you the text.

The options detailed in the man page expect you to have read the rest of the document, I guess. Here "script" just means the sed command you want to run (a substitution in your case, i.e. s/foo/bar/). Since you've only got one command, you don't need the -e option. You use -e if you want to use multiple commands.
 
1 members found this post helpful.
Old 01-22-2012, 11:09 AM   #15
GR14
LQ Newbie
 
Registered: Jan 2012
Location: Croatia
Distribution: Windows XP
Posts: 7

Original Poster
Rep: Reputation: Disabled
Is there a way to bypass the tee command, i.e. achieve the same result using only sed and its flags? In the learning materials we were given it says:

Quote:
sed flags

- used only with substitution (s)
- flags are added after the last denominator, to different effects
* /g = global pattern replacement
* /p = print out the substituted line
* /5 = substitute the 5th pattern
* /5g = substitute the 5th and every subsequent pattern
* /= = line number of the pattern occurrence
* /w file.txt = determines the output file of the sed command

flags can be combined, but /w always comes last.
And that is all on sed flags we were ever given. Now, the /w flag seems to be the one I need, because I want to write the substituted patterns in file3.txt to file 4.txt. I was thinking something like:

sed -e 's/that/THAT/2g/w file4.txt' file3.txt | less

where I though the sed -e 's/that/THAT/2g/w file4.txt' would write out the output in file4.txt. But it doesn't. I get errors. What would be the correct syntax for this particular command, i.e. how to use the /w flag?
 
  


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
difference in size of the tarred files after archiving using tar command emagnun Linux - Newbie 4 05-17-2011 07:48 AM
[SOLVED] Command line: chown command recursively on invisible directories? JZL240I-U Linux - Software 9 10-29-2010 05:34 AM
Manipulating fonts from the command line selie Linux - General 1 07-31-2010 09:50 AM
Archiving old files from /home/* directories to less expensive disk storage. Cerephim Linux - Server 6 11-06-2009 12:25 PM
Need to delete directories with files using command line FTP Zombie13 Linux - Software 2 03-10-2006 11:23 PM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration