Submit Your Article Forum Rules FAQ About Us
Search the forums:

Tech Support Team


Hello and Welcome to Tech Support Team! Before you can start posting and answering questions, you'll have to register. Registration is fast, simple and absolutely free! Feel free to browse through existing questions by choosing the forum you want to visit below.



Reply
  #1 (permalink)   Top
Old 26th February 2009, 12:14 AM
CJ1985's Avatar
TST Enthusiast
 
Join Date: Sep 2008, 295 posts.
Location: Michigan
Reputation: CJ1985 is on a distinguished road
Exclamation Need help with Linux command

I am just learning how to work in Linux, and I am getting frustrated. I'm trying to figure out what I need to do in order to be able to have a previous file that is a text file, which has 10 lines of text to do the following:

I need to be able to take the first 5 lines of the text file and move them to the bottom so that the bottom 5 lines of text are at the top and then save the file.

I figured using the head -n 5 and tail -n 5 command would work, but it is not doing what I need it to do.

I hope this makes sense? I know how to create a text file, or at least I thought I did.

Creating a text file, you would do the whole cat > myfile as an example, press enter and then start typing a note for an example. Once I'm done press enter and then ctrl+d to exit, and then to view the file I would go cat myfile which would bring it up and that does work. But if I want to take the first 5 lines of that file and move it to the bottom, and have the bottom 5 lines of that file to the top all in one file and name it a different file, wouldn't I need to use the head and tail command as mentioned above?

PLEASE HELP!! lol

I hope what I have said makes any sense at all. HA HA
__________________
"People think at the end of the day that a man is the only answer [to fulfillment]. Actually a job is better for me."
Princess Diana
Reply With Quote
  #2 (permalink)   Top
Old 27th February 2009, 01:43 AM
CJ1985's Avatar
TST Enthusiast
 
Join Date: Sep 2008, 295 posts.
Location: Michigan
Reputation: CJ1985 is on a distinguished road
I got help with this, however... I am wondering, is there anyone here who knows or uses Linux? I am so confused and lost with this, I am trying to learn it because I am in a class in college trying to learn Linux and it is not easy stuff! It's all gibberish to me. Help me! lol

No but seriously, help!!
__________________
"People think at the end of the day that a man is the only answer [to fulfillment]. Actually a job is better for me."
Princess Diana
Reply With Quote
  #3 (permalink)   Top
Old 1st March 2009, 05:48 PM
dudeking's Avatar
TST Expert
 
Join Date: Jul 2008, 583 posts.
Location: Nottingham, UK
Reputation: dudeking is on a distinguished road
To be honest I don't quite understand what you're looking to do.. id take a look at a few perl tutorials for linux command line. But if its just to find and replace this will do it.

$ perl -pi -e "s/hello/goodbye/g;" filename [RET]

This would change every occurrence of hello to goodbye in the file called filename


... any help?
Reply With Quote
  #4 (permalink)   Top
Old 7th March 2009, 06:18 PM
wladicus's Avatar
TST Expert
 
Join Date: Sep 2008, 831 posts.
Location: St. Thomas, Ontario, Canada
Reputation: wladicus is on a distinguished road
In which text editor are you trying to do this: Kate, Nano, vi ... ?
I work with Linux on and off.
As I understand it the head and tail commands only list or display the number of lines you specify either from the top or from the bottom of the file.
If you want to change something in a file there are 2 ways to do it.
The easy way is to use a text editor to open the file, look at the contents and use the text editor commands to make the desired changes. vi comes as a standard text editor in Linux, and some others are Kate, Kwrite,nano,and joe. I have used vi, Kwrite, Kate and nano.
The other way to alter a text file is via programming. You can write a routine (script file or other programme file) to perform desired functions on a text file. For example you can parse the text file to search and find a particular phrase and then do what you wish with it. You can also move lines to different places in the file. All this sort of programmed manipulation requires some detailed knowledge of file structure and programming skills, and it is probably not what you are looking for at this stage in your study.
So you probably need to use a text editor to make the changes you want. Not too different from using Notepad in Windows or more accurately it is similar to using something like EDIT.com in DOS to edit a text file.
Hope this helped some.
walt
__________________
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
joy,

walt
St. Thomas, Ontario, Canada = 42.77°N, 81.11°W =
That which appears to be without lies within...wladicus
->http://wladicus.blogspot.com/

Last edited by wladicus; 10th March 2009 at 01:49 AM.
Reply With Quote
  #5 (permalink)   Top
Old 28th March 2009, 12:30 AM
Mikorist's Avatar
TST Member
 
Join Date: Sep 2008, 70 posts.
Location: Belgrade, Serbia
Reputation: Mikorist is on a distinguished road
You must learn cat, head, tail, to do something like that...
Look:
Text Processing Commands
__________________
YouCanMail.Me
Reply With Quote
  #6 (permalink)   Top
Old 29th March 2009, 05:51 PM
wladicus's Avatar
TST Expert
 
Join Date: Sep 2008, 831 posts.
Location: St. Thomas, Ontario, Canada
Reputation: wladicus is on a distinguished road
Quote:
Originally Posted by Mikorist View Post
You must learn cat, head, tail, to do something like that...
Look:
Text Processing Commands
Good point Mikorist. Thank you for the link - I have added it to my collection on Linux.
__________________
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
joy,

walt
St. Thomas, Ontario, Canada = 42.77°N, 81.11°W =
That which appears to be without lies within...wladicus
->http://wladicus.blogspot.com/
Reply With Quote
Reply

Only registered members can participate in forum threads. You must register or log in to contribute.


Thread Tools

Forum Jump


All times are GMT. The time now is 09:28 AM.






Post A Question!
Useful Links
Main Menu
Home
Forum Rules
FAQ
About Us
Welcome Pack
Search the forums
TST Mobile
Contact Us
Send Message

These are the 18 most used thread tags
Tag Cloud
32-bit cat drivers geforce hardware intel gfxui mobile 4 chipset driers modem monitor network no ring response no signal nvidia soft modem software wifi win7 windows 7